1

I have an ajax query sending to a php script and putting the response into a div. The code is as follows:

$.ajax({
type: "POST",
url: "core/process.php",
data: data,
success: function(response){
   $("#form").fadeOut('slow');
   alert("DO NOT LEAVE THIS PAGE UNTIL COMPLETE");
   $("#response").html("DO NOT LEAVE THIS PAGE UNTIL COMPLETE<br />")
   .append(response)
   .hide()
   .slideDown('slow');
}
});

What I want to do is check the response for a string or return such as "true" or "success" or whatever and alert the user the script is complete. I know very little jQuery beyond what you see above and am not sure how to search a response for something specific.

Edit: I just realized I forgot to put how the script outputs the response. It's just echoing in the php script. I'm thinking I may need to put everything into an array and json_encode it, but that's just a guess.

2 Answers 2

2

You could use the indexOf function:

if (response.indexOf('success') > -1 || response.indexOf('true') > -1) {
    // the response contains one or both of the strings success and true
}
Sign up to request clarification or add additional context in comments.

Comments

0
if (/Success/.test(response)) {
  alert('Cool')
}

Or change the response type to json and have the server encode a status code and output string as the result object.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.