Jump to content

Recommended Posts

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...

Link to comment
https://forums.phpfreaks.com/topic/209959-ajax-basic-question/
Share on other sites

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); 

Link to comment
https://forums.phpfreaks.com/topic/209959-ajax-basic-question/#findComment-1095987
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/209959-ajax-basic-question/#findComment-1096770
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.