开发者

jquery POST method callback function query

$("#submit_js").click(function() {
            var commentmsg = $('#comment').val();
            $.post(
            "user_submit.php", 
            {comment: $("#comment").val(), aid: imgnum, uid:$("#uid").val()}, 
            function(data){
                /*alert(data);*/
                //$('#greetings').html('Your choice was submitted开发者_开发问答 successfully. Thank You for voting.');
                $('#confirm_msg').addClass("on");
                $('#care_parent').addClass("off");
                $('#fb_user_msg').html(commentmsg);
                //$('#fb_user_msg').html( commentmsg );
            });
        });

the above is my jquery POST function. in the callback function i am doing some html stuff. this is the successful POST version. that means, when the POST procedure is complete or added to the DB. now in my user_Submit.php i am checking to validate whether I should add the data to the DB or not.

Can the callback function be modified so that if I dont add to the DB in user_Submit.php, I should display some other message to the user...

what I really want to ask is, how to make PHP pass a 0/1 value ot JS? can someone help?


In your user_submit.php, just echo 1 if it was successful and 0 if not. That variable will be returned to your handler function in the data parameter. Then just do a simple if/else to see what the value was.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜