homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

AJAX and http.responseText

 6:13 pm on Sep 1, 2011 (gmt 0)

How do you check if http.responseText is empty or null? I don't want the second part, the else part, to run if it is as per the below:

if(reminderresponse === '' || reminderresponse === null)
//do nothing
window.open ("reminder-display.php?user_id="+reminderresponse,"mywindow","location=1, width=600, height=400, scrollbars=1");

I've tried == and ===

Thanks for your help in advance!



 7:08 pm on Sep 1, 2011 (gmt 0)

It will be ==

I think it only returns integers so checking for an empty string won't work.

I think you want

if(reminderresponse == 0)

or maybe

if(reminderresponse == -1)

I am going from memory so I could be mistaken


 7:42 pm on Sep 1, 2011 (gmt 0)

OK yeah that seems to have worked, thanks!


 8:15 pm on Sep 1, 2011 (gmt 0)

How do you check if http.responseText is empty or null?

I think it only returns integers...

...that seems to have worked

I think I'm missing something, what is reminderresponse?


 9:36 pm on Sep 1, 2011 (gmt 0)

I assumed it was a variable that he set the http.responseText to


 10:52 pm on Sep 1, 2011 (gmt 0)

penders... it just hit me what you are driving at.

I read this too quick and I even typed it out and still missed it. I thought we were talking about .readyState

Pico I may have led you down the wrong path, it could be that your method is returning an integer but it isn't guarenteed. If it is truly working it was a lucky stumble.

you may want to console.log(reminderresponse) and see what it contains and make sure that == 0 is what you need


 11:21 pm on Sep 1, 2011 (gmt 0)

Yep, that was my confusion. reponseText (as it's name suggests) should be text/string. If the above comparison works then I would guess there is some implicit type conversion going on, and it was quite possibly a 'lucky stumble'? For instance, if reminderresponse contained the string "0", then (reminderresponse == 0) would indeed evaluate to true because of implicit type conversion.

JAB Creations

 2:00 am on Sep 2, 2011 (gmt 0)

You shouldn't serve text files to your visitors, use responseXML instead.

With responseXML you should be able to check for childNodes.

Then you should be able to do something like...

...or count the number of childNodes...

Also avoid proprietary methods like innerHTML and stick to DOM methods like appendChild or importNode when importing AJAX loaded content in to a page otherwise you're going to deal with a lot of unreliable code and it's associated frustration.

- John

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved