开发者

code in xmlhttp.readyState==4 doen't get executed

function download() {
    if (window.XMLHttpRequest)   {// code fo开发者_运维问答r IE7+, Firefox, Chrome, Opera, Safari   
        xmlhttp=new XMLHttpRequest();
    } else   {// code for IE6, IE5  
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");  
    } 

    xmlhttp.onreadystatechange=function() 
    {   //alert(xmlhttp.readyState);
        if(xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            alert (xmlhttp.responseText);
        }   
    }

    xmlhttp.open("GET","import.php?file="+document.getElementById('uploaded_file').value,false);
    xmlhttp.send(); 

  //  location.reload(true);
}

if I put alert and monitor xmlhttp.readyState then it shows me that its status does turn 4 and it does go in the if statement, if I don't monitor it with alert then it doesn't go in the if statement but I know import.php is working because I can see the changes in the database. I don't know whats going on...can anyone help.

Thanks


thats because the location.reload(true); is reloading the page, and not waiting for the xmlhttp call to complete

UPDATE: try setting the 3rd parameter in the xmlhttp.open call to true

from the docs:

A Boolean indicator of whether the call is asynchronous. The default is True (the call returns immediately). If set to True, attach an onreadystatechange property callback so that you can tell when the send call has completed.

http://msdn.microsoft.com/en-us/library/ms757849%28v=vs.85%29.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜