我有一個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) –