ajax - if condition - jquery response -


I am using jquery-ajax to send data to a php. PHP sends a response to success or failure. So far, everything works fine. Now my question is, how do I use an if statement in jquery to perform some action using feedback?

  $ Post ("php / send.php", {email: $ ('#email') .val (), name: $ ('#name') .val ()}, function (response) {// warning (response ) If (reaction == "error a") {// do A ...} else (feedback == "errorB") {// do B ...} Else {// do C ...}) };  

If my statement does not work. Even the response from php is "error A" or "error", it would // do it. How do I fix it?

That's because the response you are retrieving is a different string than a comma and javascript It is treating it as an array.

  if (response.indexOf ("errorA") == 0) {} and if (response.indexOf ("errorB") == 0} {}  

Comments