XMLHttpRequest
使用XMLHttpRequest实现一个Ajax(Asynchronous JavaScript And XML)
第一步:获取实例
let xhr;
if(window.XMLHttpRequest){
xhr = new XMLHttpRequest();
}else{
xhr = new ActiveXObject('Microsoft.XMLHTTP');
}第二步:初始化请求
xhr.open(method, url, async, user, password)第三步:发送参数
xhr.send(body)xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xhr.send("fname=Henry&lname=Ford");第四步:处理返回结果
简约版
Last updated