首页 > js如何同步执行ajax

js如何同步执行ajax

我现在使用的是

function ajax(i,p,f){
    var x=window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP");
    x.open(p?'POST':'GET',i,1);
    x.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    x.send(p||'');
    if(f)x.onreadystatechange=f;
}

这样用是异步执行的,如何改为同步执行?


x.open(p?'POST':'GET',i,false);

open第三个参数为true时,表示是异步请求;false为同步。

【热门文章】
【热门文章】