the code below is a jquery POST request javascript. i want to use the data I am posting in the callback function. if u take a look,
$('#fb_user_msg').innerHTML = data.comment;
the above line is trying to include the comment in the html (unsuccessfully). i am sure this is easy but I dont know why I am not getting it right.
$("#submit_js").click(function() {
$.post(
"user_submit.php",
{comment: $("#comment").val(), aid: imgnum},
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').innerHTML = data.comment;
}
);
});
please help??
You would want to make a global variable before you POST your data in order to use in your callback function:
$("#submit_js").click(function() {
var comment = $('#comment').val();
$.post("user_submit.php", {comment: comment, aid: imgnum},
function(data){
$('#confirm_msg').addClass("on");
$('#care_parent').addClass("off");
$('#fb_user_msg').innerHTML = comment;
});
});
Does the service you are calling ( user_submit.php
) return the comment data in its response?
Even so, if you already have the data in another area ( #comment
), why not just take it straight from there?
$('#fb_user_msg').innerHTML = $("#comment").val();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.