现在的位置: 首页 > 综合 > 正文

AJAX (XHR)异步请求的一些认识

2013年10月01日 ⁄ 综合 ⁄ 共 491字 ⁄ 字号 评论关闭

function sendAsynchronRequest(url,parameter,callback){
 createXMLHttpRequest();
 if(parameter == null){
  xmlHttp.onreadystatechange = callback;
  xmlHttp.open("GET",url,true);//当GET请求时,在地址栏中是带参数的,而参数为NULL,所以用get请求,send(null)
  xmlHttp.send(null);
 }else{
  xmlHttp.onreadystatechange = callback;
  xmlHttp.open("POST",url,true);//get
  xmlHttp.setRequestHeader(
  "Content-Type","application/x-www-form-urlencoded;");
  xmlHttp.send(parameter);//当POST请求时,在地址栏中是wu参数的,而参数 !=NULL,所以用设置为POST请求,send(parameter)
 }
}

抱歉!评论已关闭.