javascript - AJAX xmlhttp.responseText -
i've been racking brain few hours , can't figure out why string comparison won't work. in following code, xmlhttp call , response text. php file call returning proper response string "noad"
, , noad
being displayed when appropriate in testing. however, when call returned noad
want identify it, reason within call below xmlhttp.responsetext == comparisontext
not comparing two. why xmlhttp.responsetext
printout noad can't use within comparator?
function loadxmladimage1doc(currentscenariotime) { var returntext = "not here"; var comparisontext = "noad"; var xmlhttp; if (window.xmlhttprequest) {// code ie7+, firefox, chrome, opera, safari xmlhttp=new xmlhttprequest(); } else {// code ie6, ie5 xmlhttp=new activexobject("microsoft.xmlhttp"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readystate==4 && xmlhttp.status==200) { if (xmlhttp.responsetext == comparisontext) { document.getelementbyid("ajaxtest").innerhtml =returntext; } else { document.getelementbyid("ajaxtest").innerhtml =xmlhttp.responsetext; } } }
okay, luth pointing me in right direction. solved problem, i'm not sure problem within xmlhttp.responsetext or user error caused it.
the return text php file placing unseen character before returned string (in testing, have figured invisible character after prior results go figure). theoretically, shouldn't happening...my php returning straightforward string:
..do mysql queries.. $adlink = mysql_result($result, 0); if ($adlink == "") { echo "noad"; } else { echo $adlink; }
so php file should sending 4 character return screen xmlhttp.responsetext call named "noad". found in measuring string length was sending 5 character string invisible character before "noad" wasn't showing on screen - therefore screwing comparator. used following code remove character , worked perfectly...
returntext = xmlhttp.responsetext; var returnlength = returntext.length; returntext = returntext.substring(1, returnlength);
i have no idea character is, whether problem php code or xmlhttp.responsetext call, aware of if you're dealing call.
Comments
Post a Comment