helloise Posted August 19, 2011 Share Posted August 19, 2011 here is my code: <head> <script language="JavaScript" type="text/JavaScript"> var url = "www-rainbowcode-net/index.php/messagebox/list"; function getXmlHttpRequestObject() { if (window.XMLHttpRequest) { alert("in gethttprequest"); return new XMLHttpRequest(); } else if(window.ActiveXObject) { return new ActiveXObject("Microsoft.XMLHTTP"); } else { //document.getElementById('p_status').innerHTML = 'Status: Cound not create XmlHttpRequest Object.'; } } function getNewMessage() { var receiveReq = getXmlHttpRequestObject(); alert("state is" + receiveReq.readyState); if (receiveReq.readyState == 4 || receiveReq.readyState == 0) { alert("state is" + receiveReq.readyState); //var params = "name" + name + "&" + "comment=" + comment; receiveReq.open("POST", url, true); receiveReq.onreadystatechange = processReqChange(); receiveReq.send(null); } } function processReqChange() { alert("processed" + receiveReq.responseText); if (receiveReq.status == 200) { alert("processed" + receiveReq.responseText); document.getElementById("message_area").innerHTML = receiveReq.responseText; } else { alert("There was a problem retrieving the XML data:\n" + receiveReq.statusText); } setTimeout('getNewMessage();',2000); } </script></head> <body onload="getNewMessage();"> //more code</body> none of the alerts are executing?? i dont understand..all i want is make sure everything executes as it should so that my page/part of my page(div part) can refresh so that the user can constatnly receive and be aware of new message that came inplease help?thanks Link to comment Share on other sites More sharing options...
JamesB Posted August 19, 2011 Share Posted August 19, 2011 remove the 2 brackets ( ) from this line, as the onreadystatechange property should be set to a function, not the value the function returns. receiveReq.onreadystatechange = processReqChange(); move this if statement: if (receiveReq.readyState == 4 || receiveReq.readyState == 0) into the processReqChange() function.then remove "var" from this line, which will make the receiveReq variable global, so it can be accessed in the processReqChange() function. var receiveReq = getXmlHttpRequestObject(); Link to comment Share on other sites More sharing options...
justsomeguy Posted August 19, 2011 Share Posted August 19, 2011 You might also want to verify the URL you're trying to send a request to. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.