views:

465

answers:

4

Hello, I am making a request to a CGI program using AJAX. The response sends me content-length. My purpose is to dynamically exhibit the response progress. For that I need to start a function on onreadystate value of XHR object to be 3. But the request doesn't seems to acquire that status number. Instead it goes directly from state 1 to state 4. What am I missing?

A: 

The response could be going so quickly that you just don't notice it at state 3. Especially if you are running it on localhost, the response could be transmitted very quickly. You could try setting an alert when it gets to stage 3 to test whether it's actually getting there. Also, I belive internet explorer says that it is a mistake to access the response in stage 3 so there could be compatibility issues.

A: 

Hi brian Thanks for the reply. Actually, I am writing logs to console of firebug. And I don see a state of 3 . It goes directly to state 4. Yep, I am on localhost. So the response is fast. Is it imperative that it has to go through all the state numbers? viz. 1,2,3,4.

Thanks.

Rakesh
A: 

If you're running on localhost, then probably the browser is never getting a chance to run between the time it sends the request and the time it gets the response...

  1. browser opens connection, sets readyState to 1
  2. browser sends packet to server process
  3. server process receives packet, gets priority from scheduler
  4. server returns data to browser, and yields control of the CPU. Browser continues execution.
  5. browser sees all data has been received, sets readyState to 4.

Long story short: don't count on going into the "receiving" state.

Yuliy
A: 

Cool. You mean, things are happening real fast, therefore it doesn't goes to state = 3. It should work for a remote system ?

Rakesh