方法
,那么,ajax如何实现呢?如下是一个比较完整的ajax()function createxmlHttpRequest() {
if (window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
} else if (window.XMLHttpRequest) {
return new XMLHttpRequest();
}
}
if (window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
} else if (window.XMLHttpRequest) {
return new XMLHttpRequest();
}
}
function convertData(data){
if( typeof data === 'object' ){
var convertResult = "" ;
for(var c in data){
convertResult+= c + "=" + data[c] + "&";
}
convertResult=convertResult.substring(0,convertResult.length-1)
return convertResult;
}else{
return data;
}
}
使用格式跟jquery的ajax差不多:
PHP",dataType:"json",data:{"val1":"abc","val2":123,"val3":"456"},beforeSend:function(){
//some js code
},success:function(msg){
console.log(msg)
},error:function(){
console.log("error")
}
})
原文链接:https://www.f2er.com/ajax/45708.html