Advertisement
Guest User

Untitled

a guest
Sep 14th, 2010
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function ajaxXHR() {
  2.     var xhr = null;
  3.     if (window.XMLHttpRequest || window.ActiveXObject) {
  4.         if (window.ActiveXObject) {
  5.             try {xhr = new ActiveXObject("Msxml2.XMLHTTP");}
  6.             catch(e) {xhr = new ActiveXObject("Microsoft.XMLHTTP");}
  7.         }
  8.         else xhr = new XMLHttpRequest();
  9.     } else return null;
  10.     return xhr;
  11. }
  12.  
  13. function ajaxLoad(req_url, data)
  14. {
  15.     var xhr = ajaxXHR();
  16.     if (xhr == null) {
  17.         alert("ajaxLoad(): XMLHTTPRequest isn't supported by your browser.");
  18.         exit(); //it will stop the script's execution because exit() isn't recognized by the interpreters.
  19.     }
  20.    
  21.     xhr.open("POST",req_url,false);
  22.     xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  23.    
  24.     xhr.send(data);
  25.     if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) return xhr.responseText;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement