function ajax(ops){
ops.method= ops.method || "get";
ops.data = ops.data || "";
ops.url = ops.method=="get" ? ops.url + "?" + ops.data : ops.url;
var xhr = new XMLHttpRequest();
xhr.open(ops.method, ops.url);
if(ops.method== "get"){
xhr.send();
}else{
xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xhr.send(ops.data);
}
xhr.onreadystatechange = function(){
if(xhr.readyState === 4 && xhr.status === 200){
ops.success(xhr.responseText);
}
}
}
AJAX的基础封装
猜你喜欢
转载自blog.csdn.net/weixin_42881768/article/details/104801415
今日推荐
周排行