So I am getting some data via AJAX, from a Java servlet on the server side.
I had some alert boxes set up, and the request gets submitted only once.
But, the callBack function in the onreadystatechange iterates through the states twice - reaches state == 4 , status == 200, does its work, and then goes through the states again... I have no idea why this is happening?
Here is the code:
Code:function createRequest() { try { request = new XMLHttpRequest(); } catch(tryMS) { try { request = new ActiveXObject("Msxml2.XMLHTTP"); } catch(otherMS) { try { request = new ActiveXObject("Microsoft.XMLHTTP"); } catch(failed) { request = null; } } } return request; }Code:function getSubmitRequest() { //Create request object req1 = createRequest(); if(req1 == null) { alert("Unable to create request"); return; } //Configure request object var url = "/ajaxurl"; req1.open("POST",url,true); //Tell the request object what to do when server responds -assign a call-back function req1.onreadystatechange = populatePage; //Make the request req1.send(null); }
Code:function populatePage() { if(req1.readyState == 4) { if(req1.status == 200) { var responseDoc = req1.responseXML; populatePageParts(responseDoc); } } }


Reply With Quote

Bookmarks