Jezevec Posted May 14, 2009 Share Posted May 14, 2009 Hi everyone, I have this kind of troubles: Using this code: function getXMLHttp() { if(window.XMLHttpRequest) { return new XMLHttpRequest(); } else if(window.ActiveXObject) { return new ActiveXObject("Microsoft.XMLHTTP"); } return null; } function MyFunc(id) { xmlhttp=getXMLHttp(); if(xmlhttp==null) { alert("Error creating XMLHttp Request."); return; } xmlhttp.open("GET","file_returning_sent_variable.php",true); xmlhttp.send(null); xmlhttp.onreadystatechange=function() { if(xmlhttp.readyState==4) { alert(xmlhttp.responseText); } } } When I call the MyFunc from main window, it works regularly. But when I open a new window using window.open method and within this I call the same function (using the same script in the same external *.js file attached in html head), it doesn't work anyway. Trying alert xmlhttp.status, it's 200 in case of the main window, but 0 in case the newly opened window. So tell me, where's the bug? thanks for answers Jezevec Quote Link to comment Share on other sites More sharing options...
Jezevec Posted May 14, 2009 Author Share Posted May 14, 2009 And I can answer myself :-) The bug was not inside the AJAX requesting but in the code of opened window - teh event used to call MyFunc was like this: //... onclick="MyFunc();location.href=location.href;" //... Where the location.href is used to refresh the page, but this function don't wait for AJAX response and just refresh the page, which means the response data are lost. I worked around this by replacing the refresh inside the block of if(xmlhttp.readyState==4) condition. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.