After pondering for a few hours, I am stuck trying to understand why a simple string comparison is not working. In the code snippet below, I perform an XMLHttpRequest and receive a response text. The PHP file being called returns the correct response string "NOAD", which is also displayed correctly in my testing scenarios. However, when the call returns "NOAD", I try to compare it using
xmlhttp.responseText == comparisonText
, but for some reason it fails to match the two strings. Even though xmlhttp.responseText
prints out "NOAD," I can't seem to use it within the comparator.
function loadXMLAdImage1Doc(currentScenarioTime) {
var returnText = "Not Here";
var comparisonText = "NOAD";
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest();
} else {
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;
}
}
}
}