Reputation: 970
So what I am doing is I am calling a ajax post to a php file, and what that php file does it is echo's out data, which I retrieve through a variable data, the problem is when I go to compare that a string it never is successful. Here's some code:
Javascript Code
$.post("CheckStarted.php", {
check: 10
}, function(data, status){
if(data.toString() == "start"){
JSFunct();
}else{
//do something else.
}
console.log(data);
});
So as you can see I am checking to see if it is equal to "start" so that will start my JSFunct, the problem is every time the console, log's start or stop and even if it logs stop(because of the console.log(data)
) it will always not be equal to start even if start is logged to the console? What is going on here, and if this is not the best way to do it how would you compare this reponse. Thank you.
Upvotes: 1
Views: 39
Reputation: 70
There may be white space in string check like this:-
if( data.trim() == 'start' ) {
//code
}
or
if( data.search("start") != -1 ) {
//code
}
Upvotes: 1