开发者

How do I make my PHP AJAX code return false into my false jQuery block?

开发者 https://www.devze.com 2023-04-11 13:57 出处:网络
I have some jQuery that looks like this: $.ajax({ type: \"POST\", url:开发者_JS百科 \"/problems/vote.php\",

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

0

精彩评论

暂无评论...
验证码 换一张
取 消