noamkrief Posted February 11, 2009 Share Posted February 11, 2009 Hi, i've been having this crazy inconsistent issue with Ajax / php and IE. Here is my code: function Inint_AJAX() { //try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {} //IE //try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE try { return new XMLHttpRequest(); } catch(e) {} //Native Javascript alert("XMLHttpRequest not supported"); return null; }; function savemyform(f) { var i = 0 var param = ""; while (i < f.elements.length) { // alert(f.elements[i].type); if (f.elements[i].type == 'submit' || f.elements[i].type == 'button' || f.elements[i].type == undefined) { } else { if (f.elements[i].type == 'checkbox') { if (f.elements[i].checked == true) { param = param + f.elements[i].name + "=" + f.elements[i].value +"&" } } else { param = param + f.elements[i].name + "=" + encodeURIComponent(f.elements[i].value) +"&" } } i++; } var req = Inint_AJAX(); req.onreadystatechange = function () { if (req.readyState==4) { if (req.status==200) { try { if (req.responseText == 1) { document.getElementById('savemessage').innerHTML = 'saved succesfully...'; } else if (req.responseText == 2) { alert('Duplicate. Saving failed!'); } else { alert('Saving Failed... Timeout Error.'); } setTimeout('deletesetmessage()', 500) } catch(e) { } } } }; var url = "./save.php"; req.open("POST", url, true); //Send the proper header information along with the request req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); req.setRequestHeader("Content-length", param.length); req.setRequestHeader("Connection", "close"); req.send(param); } function deletesetmessage() { document.getElementById('savemessage').innerHTML = ""; } So, when i click "save" in the webpage, there is a div where it displays "saved succesfully..." Sometimes when the internet connection is slow like on a verizon EVDO card, nothing happens when i click the save button. If I do this more than twice, IE freezes completely and the entire web application crashes. I have to open new IE and login from scratch. I think my init_AJAX needs a timeout perhaps? Right now it would loop for all eternaty and i've read that IE can only handle 2 requests at the same time. I'd really appreciate input - i'm pretty new with ajax and don't really understand the javascript behind it. Thanks Noam Quote Link to comment Share on other sites More sharing options...
noamkrief Posted February 11, 2009 Author Share Posted February 11, 2009 I think I got it, but let me know if it makes any sense. Once I removed this line: req.setRequestHeader("Connection", "close"); I couldn't replicate my issue any more. So I did some google searches on this string "setRequestHeader("Connection", "close");" and found many sites talking about IE hanging. What a conincedense right??? Can anyone explain why this line would have been the issue? Thanks 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.