Readystate is always 0, indicating that the object has been established and the connection has not been established.
Code I wrote:
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(); } }
It was finally solved because the sentence XMLHTTP. onreadystatechange = changestate (); in this case, XMLHTTP. onreadystatechange is to assign the returned value of changestate to XMLHTTP. onreadystatechange; while XMLHTTP. onreadystatechange indicates that the changestate function is called when the status changes. Therefore, the following code should be written: XMLHTTP. onreadystatechange = changgestate. If there is a parameter, write it as follows: XMLHTTP. onreadystatechange = functiong () {changestate (a, B );};