function ajax(method, url, data,fn) {
let htp = null;
try {
htp = new XMLHttpRequest()
}
catch (err) {
htp = new ActiveXObject("Microsoft.XMLHTTP")
}
if (method == "get") {
htp.open(method, url +"?"+ data);
htp.send()
} else {
htp.open(method, url);
htp.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
htp.send(data)
}
htp.onreadystatechange = function () {
if (htp.readyState == 4 && htp.status == 200) {
fn(htp.responseText)
}
}
}
AJAX的封装 可以直接用
猜你喜欢
转载自blog.csdn.net/weixin_44081699/article/details/86466326
今日推荐
周排行