Advertisement
Guest User

Untitled

a guest
May 27th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. function request(url, postdata, async, method){
  2.  
  3. var http = new XMLHttpRequest();
  4. var query;
  5.  
  6. http.open(method, url, async);
  7. //Send the proper header information along with the request
  8. http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  9.  
  10. http.onreadystatechange = function() {//Call a function when the state changes.
  11.  
  12. if(http.readyState == 4 && http.status == 200){
  13. console.log("successfully request \nURL:"+url+"\n STATUS:"+http.status+"\nPOST:"+postdata+"\nAnswer:"+http.responseText)
  14. query = http.responseText;
  15. }
  16. else if(http.readyState == 4 && http.status >= 400 || http.status >= 300){
  17. console.log("send request error or network error \nURL:"+url+"\nPOST:"+postdata+"\nAnswer:"+http.responseText)
  18. return request(url, postdata, async, method);
  19. }
  20. }
  21.  
  22. http.send(postdata);
  23.  
  24. return query;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement