How do I make my PHP AJAX code return false into my false jQuery block?
I have some jQuery that looks like this:
$.ajax({
type: "POST",
url:开发者_JS百科 "/problems/vote.php",
dataType: "json",
data: dataString,
success: function(json)
{
// ? :)
}
error : function()
{
alert("ajax error");
}
});
when I am writing my AJAX code, in case of some validation or database errors, I want to stop execution and return to the jQuery error block. What do I have to do in the PHP AJAX code in order to return things to the error block instead of the success block?
Thanks!!
you'd have to use the success function and capture what is returned for example:
$.ajax({
type: "POST",
url: "/problems/vote.php",
dataType: "json",
data: dataString,
success: function(json)
{
if(json == "error"){
alert("error");
}
}
});
you'll only use error:
if there is a problem with the AJAX request
精彩评论