Welcome to WebmasterWorld Guest from 54.161.255.61

Forum Moderators: open

AJAX and http.responseText

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

10+ Year Member



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
}else{
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)

WebmasterWorld Senior Member demaestro is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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)

10+ Year Member



OK yeah that seems to have worked, thanks!
8:15 pm on Sep 1, 2011 (gmt 0)

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



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)

WebmasterWorld Senior Member demaestro is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I assumed it was a variable that he set the http.responseText to
10:52 pm on Sep 1, 2011 (gmt 0)

WebmasterWorld Senior Member demaestro is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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)

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



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.
2:00 am on Sep 2, 2011 (gmt 0)

WebmasterWorld Senior Member jab_creations is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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...
alert(xml_object.childNodes[0].nodeValue.length);


...or count the number of childNodes...
alert(xml_object.childNodes.length);


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
 

Featured Threads

Hot Threads This Week

Hot Threads This Month