我的页面上有多个表单。当我点击表单提交按钮时,我想通过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