ajaxiskey Posted August 6, 2010 Share Posted August 6, 2010 Can someone please explain the complete ajax request in high detail. 0: request not initialized 1: server connection established 2: request received 3: processing request 4: request finished and response is ready The point of me asking this question is that I must know when the PHP code on the page I called has finished being processed... Quote Link to comment Share on other sites More sharing options...
JonnoTheDev Posted August 6, 2010 Share Posted August 6, 2010 It is complete when the readyState is 4 (as you have showed in your document). There will also be a status of 200. Example: // start ajax object var req = Inint_AJAX(); // check request status req.onreadystatechange = function () { // request is complete if (req.readyState==4) { // status ok if (req.status==200) { alert('finished processing'); } } }; // make connection req.open("GET", "/phpfile.php"); // set header req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1"); // send value req.send(null); Quote Link to comment Share on other sites More sharing options...
ajaxiskey Posted August 7, 2010 Author Share Posted August 7, 2010 When does the php code on the requested page start running, and end running... readyState wise? Quote Link to comment Share on other sites More sharing options...
JonnoTheDev Posted August 8, 2010 Share Posted August 8, 2010 When does the php code on the requested page start running, and end running... readyState wise? As soon as the javascript function containing the request is called, usually through an event handler such as onClick() i.e the user clicks a button. When the readyState value is 4 the script has completed. 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.