我的頁面上有多個表單。當我點擊表單提交按鈕時,我想通過ajax發送只有該表單的表單值。這是我的。第一種形式的工作原理與第二種形式實際提交表格一樣。我怎樣才能單獨針對每個表單。我覺得我應該在某處使用.find()。針對多個表單發送通過ajax(jquery)
<form id="form1" method="post">
<input type="text" id="name1" name="value" value="">
<input type="submit" id="update_form" value="Save Changes">
</form>
<form id="form2" method="post">
<input type="text" id="name2" name="value" value="">
<input type="submit" id="update_form" value="Save Changes">
</form>
<script>
// this is the id of the submit button
$("#update_form").click(function() {
$.ajax({
type: "POST",
url: "approve_test.php",
data: $(this.form).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.
});
</script>
不要使用相同的id元素。 –
可能的重複:http://stackoverflow.com/questions/15419022/submitting-multiple-forms-via-ajax-sync-or-async – ZimSystem
@Skelly我真的看到了,但他想用一個按鈕提交多個表單。每個表單都有一個提交按鈕。 – vinylDeveloper