我有一个PHP脚本,通过点击链接触发的AJAX调用来调用。通常情况下,我只是使用表单并将所有表单数据传递给我的PHP脚本,但我想通过AJAX手动发送POST数据,这样我就可以避免使用表单。我怎样才能做到这一点?将POST数据发送到不带表格的AJAX
我的JQuery/AJAX:
$(".likes-count a").click(function() {
var post= $(this).parents(".post-bottom").find('.comment-input').val();
// this value is from another form, this is the value that I need in my PHP script
// grabs and updates the comment count
$.ajax({
type: "POST",
url: "myscript.php",
data: 'post-id' : post, // This is what I have tried so far
success: function(html) {
alert(html);
}
});
});
可能重复 - $ .ajax POST不会将.data发送到Web服务器](http://stackoverflow.com/questions/5596341/jquery-ajax-post-does-not-send-data-to-web-server) –