views:

51

answers:

1
$("#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?

+1  A: 

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.

Tatu Ulmanen
doesnt work. if i alert(data); nothing happens.
amit
It should work. Are you sure you are outputting the success code properly? What happens if you visit `user_submit.php` with your browser? (You should see a `0`)
Tatu Ulmanen
i am doing echo 0; and it is appearing fine in firebug console. but somehow if i alert(data); nothing appears. also i tried checking the if/else part too, but nothing happens.
amit
when i alert(data); it shows, <html><body> 0 </body></html>
amit
solved. the php file had the <html><body> part.
amit