Avatar of UnexplainedWays
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?

Thanks.
JavaScript

Avatar of undefined
Last Comment
system_down

8/22/2022 - Mon
system_down


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

ASKER
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.
ASKER CERTIFIED SOLUTION
netsmithcentral

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
system_down

OK,

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

S_D
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck