Why does my Ajax request go directly from state 1 to 4?

I am making a request to a CGI program using AJAX. The response sends me content. My goal is to dynamically show the progress of the response. To do this, I need to run the onreadystate function on the XHR object's value of 3. But the request doesn't seem to get that status number. Instead, it goes directly from state 1 to state 4. What am I missing?

0


source to share


2 answers


The response can be so fast that you simply do not notice it in state 3. Especially if you are using it on localhost, the response can be transmitted very quickly. You can try setting up an alert when he gets to stage 3 to check if he actually got there. Also, I believe the internet researcher is saying that it is wrong to access the answer in the third step so that compatibility issues could arise.



0


source


If you are running on localhost, then the browser will probably never be able to start between the time the request is sent and the time it receives the response ...

  • browser opens connection, sets readyState to 1
  • the browser sends a batch process.
  • the server process receives the packet, gets priority from the scheduler
  • the server returns data to the browser and gives control of the processor. The browser continues execution.
  • the browser sees that all data has been received, sets the readyState to 4.


In short: don't expect to get into an "accepting" state.

0


source







All Articles