function Ajax(type, url, param, onsucess) {
var xhr;
if (XMLHttpRequest) {
xhr = new XMLHttpRequest();
} else {
xhr = ActiveXObject("XMLHttpRequest");
}
if (type == "Get" || type == "get") {
xhr.open("Get", url, true);
} else {
xhr.open("Post", url, true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
}
xhr.send(param);
xhr.onreadystatechange = function (data) {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
onsucess(xhr.responseText);
}
}
};
}
用JS封装AJAX请求 XMLHttpRequest (面试前记得复习)
最新推荐文章于 2024-12-02 19:35:52 发布
338

被折叠的 条评论
为什么被折叠?



