Guest User

Untitled

a guest
Feb 19th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         function callApi(params, callback){
  2.                 var xhr = new XMLHttpRequest();
  3.  
  4.                 xhr.onreadystatechange = function(){
  5.                         if(this.readyState == 4){
  6.                                 callback(this.responseText);
  7.                         }
  8.                 }
  9.  
  10.                 var post = "";
  11.                 if(params.post != null){
  12.                 for(var key in params.post){
  13.                         var val = params.post[key];
  14.  
  15.                         post += "&" + key + "=" + val;  
  16.                        
  17.                 }
  18.  
  19.                 post = post.substr(1, post.length);
  20.                 }
  21.                 xhr.open(params.type, '/index.php?option=com_apicart&task=' + params.method);
  22.                 xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  23.                 xhr.setRequestHeader("Content-length", post.length);
  24.                 xhr.setRequestHeader("Connection", "close");
  25.  
  26.                 xhr.send(post);
  27.         }
Add Comment
Please, Sign In to add comment