第一步得到(XMLHttpRequest)
function creatXMLHttpRequest(){
try{
return new XMLHttpRequest();
} catch(e){
try{
return new ActiveXObject(Msxml2.XMLHTTP);
}catch{
try{
return new ActiveXObject(Microsoft.XMLHTTP);
}catch(e){
alert("你的浏览器不支持AJax")
throw e;
}
}
}

第二步打开与服务器连接
var xmlHttp = creatXMLHttpRequest();
xmlHttp.open();
用来建立与服务器的连接有三个参数
请求方式GET或POST
url:指定服务器资源
第三个参数如果为true则异步
第三步发送请求
xmlHttp.send(null):如果不给可能会造成部份浏览器无法发送!
> 参数:就是请求体内容!如果是GET请求,必须给出null。

第四步
获取请求状态
xmlHttp.onreadystatuschange="myfunction";
得到xmlHttp的状态
var state = xmlHttp.readyState();
得到服务器的响应状态吗
ar status = xmlHttp.status();
*得到服务器的响应内容
var content = xmlHttp.response.Texxt;//文本格式内容
var content = xmlHttp.response.XML;//xml的内容
function myfunction(){
if(state == 4&&status==200){

}
}

相关文章:

  • 2022-02-08
  • 2021-07-01
  • 2022-03-01
  • 2021-07-25
  • 2021-06-20
  • 2022-12-23
  • 2021-06-23
  • 2021-07-30
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-02
  • 2021-08-30
  • 2021-11-15
  • 2022-12-23
相关资源
相似解决方案