I'm trying to compare two strings which seems containing the same value but it doesn't work.
here is my code:
ABC.prototype.is_in_DB = function () {
var ans = "";
if (window.XMLHttpRequest) {
var xmlhttp = new XMLHttpRequest();
} else {
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
ans = (xmlhttp.responseText);
}
return ans;
}
xmlhttp.open("POST", "ABC_DB.php", false);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.send("id=" + this.get_id() + "&name=" + this.get_type() + "&description=" + this.get_description() + "&kind=" + this.get_kind());
var check = "true";
console.log("this is ans type " + typeof (ans));
console.log("this is ans length " + ans.length);
console.log("this is ans " + ans);
console.log("this is check type " + typeof (check));
console.log("this is check length " + check.length);
console.log("this is check " + check);
if (ans === check) {
console.log("the if is true ");
return true;
} else {
console.log("the if is false ");
return false;
}
}
the php file works and it's end looks like this (there are no more echo commands in the file)
if ($row_cnt>0){
echo('true');
} else {
echo('false');
}
when I'm printing the values of the strings i receive the following
this is ans type string
this is ans length 5
this is ans true
this is check type string
this is check length 4
this is check true
the if is false
Do you have any idea how I can compare it?
ans.trim() == check