Leandro Zhuzhi
Leandro Zhuzhi

Reputation: 314

How to check ajax response against a string

I have a very simple ajax call, but i have problems when trying to check the returned text against a string:

// in my php file
echo 'mystring';

// in my javascript
if((request.readyState == 4) && (request.status == 200)){
  if(request.responseText == "mystring"){
    // stuff
  }else{
    //other stuff
  }
}

When i try to print request.responseText it prints the expected string, "mystring". But when i try to check it, it doesn't evaluate to true ("other stuff" is executed). Any ideas? Thanks!

Upvotes: 0

Views: 2924

Answers (1)

Anirudh Ramanathan
Anirudh Ramanathan

Reputation: 46768

Try request.responseText.trim() === "mystring"

Upvotes: 2

Related Questions