Created
September 29, 2010 12:52
-
-
Save thinkphp/602694 to your computer and use it in GitHub Desktop.
AJAX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(typeof asyncRequest == 'undefined') { | |
asyncRequest = {}; | |
} | |
asyncRequest.REQUEST = function() { | |
function handleReadyState(o,callback) { | |
o.onreadystatechange = function() { | |
if(o.readyState == 4) { | |
if(o.status == 200) { | |
callback(o.responseXML); | |
} | |
} | |
} | |
} | |
var XHR = function() { | |
var http; | |
try { | |
http = new XMLHttpRequest(); | |
XHR = function(){return new XMLHttpRequest();} | |
}catch(e) { | |
try { | |
http = new ActiveXObject("Microsoft.XMLHTTP"); | |
XHR = function(){return new ActiveXObject("Microsoft.XMLHTTP");} | |
}catch(e){} | |
} | |
return XHR(); | |
} | |
return function(method,url,callback,postData) { | |
var http = XHR(); | |
http.open(method,url,true); | |
if(postData) { | |
//Send the proper header information along with the request | |
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); | |
http.setRequestHeader("Content-length", postData.length); | |
http.setRequestHeader("Connection", "close"); | |
} | |
handleReadyState(http,callback); | |
http.send(postData || null); | |
return http; | |
} | |
}(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment