Advertisement
Guest User

ajax.js

a guest
Feb 1st, 2011
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var Ajax = new Object();
  2.    
  3. Ajax.getXHR = function() {
  4.     var http;
  5.     try {
  6.         http = new XMLHttpRequest;
  7.             Ajax.getXHR = function() {
  8.                 return new XMLHttpRequest;
  9.             };
  10.     }
  11.     catch(e) {
  12.         var msxml = [
  13.             'MSXML2.XMLHTTP.3.0',
  14.             'MSXML2.XMLHTTP',
  15.             'Microsoft.XMLHTTP'
  16.         ];
  17.         for (var i=0, len = msxml.length; i < len; ++i) {
  18.             try {
  19.                 http = new ActiveXObject(msxml[i]);
  20.                 Ajax.getXHR = function() {
  21.                     return new ActiveXObject(msxml[i]);
  22.                 };
  23.                 break;
  24.             }
  25.             catch(e) {}
  26.         }
  27.     }
  28.     return http;
  29. };
  30.  
  31. Ajax.handleReadyState = function(o, callback) {
  32.     if (o && o.readyState == 4 && o.status == 200) {
  33.         if (callback) {
  34.             callback(o);
  35.         }
  36.     }
  37. };
  38.  
  39.  
  40. Ajax.call = function(method, uri, callback, postData) {
  41.     var http = Ajax.getXHR();
  42.     http.onreadystatechange = function(){Ajax.handleReadyState(http, callback)};
  43.     http.open(method, uri, true);
  44.     //if(method=='POST'){http.setRequestHeader('Content-type','application/x-www-form-urlencoded; charset=utf-8');}
  45.     http.send(postData || null);
  46.     return http;
  47. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement