Ajax--readyState一直为0
生活随笔
收集整理的這篇文章主要介紹了
Ajax--readyState一直为0
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
readyState 一直為0表示對象已建立,連接未建立的狀態
我寫的代碼:
function LoadXMLDoc(url,scope,orderID){if(window.XMLHttpRequest){xmlhttp = new XMLHttpRequest();}else if(window.ActiveXObject){xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");}alert(xmlhttp);if(xmlhttp!=null){xmlhttp.onreadystatechange = changeState();xmlhttp.open("post",url,true);xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");xmlhttp.send("scope="+scope+"&orderID="+orderID);}}function changeState(){alert("q");alert('state:'+xmlhttp.readyState);alert('status:'+xmlhttp.status);if(xmlhttp.readyState==4 && xmlhttp.status==200){alert("Q");window.location.reload();}}后來終于解決了,是因為這句:xmlhttp.onreadystatechange = changeState();這樣寫的話xmlhttp.onreadystatechange為將changeState的返回值賦給xmlhttp.onreadystatechange;而xmlhttp.onreadystatechange為當狀態改變時調用函數changeState,所以應該這樣寫:xmlhttp.onreadystatechange=changgeState,如果有參數的話這樣寫:xmlhttp.onreadystatechange = functiong (){changeState(a,b);};
轉載于:https://www.cnblogs.com/luoyanli/archive/2012/10/08/2714927.html
總結
以上是生活随笔為你收集整理的Ajax--readyState一直为0的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C02-程序设计基础提高班(C++)第7
- 下一篇: bloom(转)