I'm using Jquery's ajax method, and I need help parsing data coming back from backend server.
server response will be either "valid" or "not valid.
Currently my "if statement logic is not working, this is what I have tried so far).
$.ajax({
url: 'php/phone-valid.php',
type: 'POST',
data: {userid: $.trim($('#userid').val())},
success: function(data) {
console.log(data);
if (result.indexOf("not valid")) {
("#mustbevalid").val("You must validate your phone number");
console.log("Phone hasn't been validated");
e.preventDefault();
};
}
});
Your help is highly appreciated.
if(data=="valid")would seem more logical thanif(result.indexOf("not valid"))...resultis undefined.