87,990
社区成员
发帖
与我相关
我的任务
分享
/*
$.ajax({
url : 'test.asp',
method : 'get',
data : {name:123},
onSuccess : function(data){
//
},
onLoad : function(){
//
},
onError : function(){
//
}
})
*/
var $ = function(){}
$.ajax = function(obj){
var url = obj.url;
var method = obj.method || 'get';
var async = obj.async || true;
var xmlHttp;
try{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}catch(e){
// Internet Explorer
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
//alert("您的浏览器不支持AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange = function(){
if(xmlHttp.readyState == 4){
if(xmlHttp.status==200){
// success
}else{
// error
}
}else{
//loading
}
}
xmlHttp.open(method, url, async);
xmlHttp.send(null);
}
$.ajax({
url : 'test.asp',
method : 'get',
data : {name:123},
onSuccess : function(data){
//
},
onLoad : function(){
//
},
onError : function(){
//
}
})
var $ = function(){}
$.ajax = function(obj){
var url = obj.url;
var method = obj.method || 'get';
var async = obj.async || true;
var xmlHttp;
try{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}catch(e){
// Internet Explorer
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
//alert("您的浏览器不支持AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange = function(){
if(xmlHttp.readyState == 4){
if(xmlHttp.status==200){
obj.onSuccess(xmlHttp.responseText)
}else{
obj.onError();
}
}else{
obj.onLoad();
}
}
xmlHttp.open(method, url, async);
xmlHttp.send(null);
}