Link to home
Start Free TrialLog in
Avatar of UnexplainedWays

asked on

AJAX: .readyState and .status

I've always used this code:

if (ajax.readyState == 4 || ajax.readyState == 'complete')
    if(ajax.status == 200)
          //then use the responseText here

However i've had to change my code to now use Response.Close() and not Response.End() (another Q, i can post link if your interested).  When i use .Close() tis status now fails.  Is this line really needed?

Avatar of system_down
Flag of Switzerland image

What do you mean? try to be more specific please...
Avatar of UnexplainedWays


Well, i learnt how to write AJAX from reading quite alot of examples.

Just about every example i read just used if(ajax.readyState == 4){ do stuff };

However, i was writing a wrapper so i wanted to make sure i had a really nice solution that would be sure to work, and i found other things that people used, like (ajax.readyState == 'complete') and also if(ajax.status == 200) like in the example above.

This has worked fine now for quite some time, but i am having problems with the body onunload and Response.End().  It seems to be changing the value of the status.

Normally i just used Response.End() in the aspx.cs file that the ajax page calls, however i now need to use .Close() aswell because it keeps crashing.

However, if i use .Close() the status is no longer 200, and the code breaks.

So my question is, would it be a better programming solution to leave the status in and find a work around, or should i just ditch it because readyState is quite sufficent.
Avatar of netsmithcentral
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

if I understood your situation:
- you are calling an aspx page via ajax and it happens that it crashes (the aspx page)
- the status isnt 200

So, the problem is inside the asp page