可能重複:
submitting form and variables together through jquery發送通過Ajax的jQuery調用參數服務器
我使用下面的代碼通過Ajax將表單數據發送到服務器,jQuery的:
// this is the id of the submit button
$("#submitButtonId").click(function() {
var url = "path/to/your/script.php"; // the script where you handle the form input.
$.ajax({
type: "POST",
url: url,
data: $("#idForm").serialize(), // serializes the form's elements.
success: function(data)
{
alert(data); // show response from the php script.
}
});
return false; // avoid to execute the actual submit of the form.
});
如果我必須發送自己的參數/值,而不是發佈表單數據,我該怎麼做? 謝謝。