最小的AJAX类库 microajax
[08-23 22:11:04] 来源:http://www.duoxue8.com JAVA教程 阅读:574次
最小的AJAX类库 microajax,标签:JAVA编程技巧,java培训,java视频教程,http://www.duoxue8.com
最小的AJAX类库
One of the smallest and easiest AJAX libraries
使用方法:
microAjax("/resource/url", function (res) {
alert (res);
});
alert (res);
});
服务端:
if ($_SERVER['X-Requested-With'] == 'XMLHttpRequest') {
// do something clever
}
// do something clever
}
源代码:
// microAjax by Stefan Lange-Hegermann
// this code is in the public domain
// you can do with it whatever you want!
function microAjax(url, callbackFunction)
{
this.bindFunction = function (caller, object) {
return function() {
return caller.apply(object, new Array(object));
}
}
this.stateChange = function (object) {
if (this.request.readyState==4) {
this.callbackFunction(this.request.responseText);
}
}
this.getRequest = function() {
if (window.ActiveXObject)
return new ActiveXObject('Microsoft.XMLHTTP');
else if (window.XMLHttpRequest)
return new XMLHttpRequest();
else
return false;
}
if (arguments[2])
this.postBody = arguments[2];
else
this.postBody="";
this.callbackFunction=callbackFunction;
this.url=url;
this.request = this.getRequest();
if
// this code is in the public domain
// you can do with it whatever you want!
function microAjax(url, callbackFunction)
{
this.bindFunction = function (caller, object) {
return function() {
return caller.apply(object, new Array(object));
}
}
this.stateChange = function (object) {
if (this.request.readyState==4) {
this.callbackFunction(this.request.responseText);
}
}
this.getRequest = function() {
if (window.ActiveXObject)
return new ActiveXObject('Microsoft.XMLHTTP');
else if (window.XMLHttpRequest)
return new XMLHttpRequest();
else
return false;
}
if (arguments[2])
this.postBody = arguments[2];
else
this.postBody="";
this.callbackFunction=callbackFunction;
this.url=url;
this.request = this.getRequest();
if