我的页面上有多个表单。当我单击表单提交按钮时,我想通过 ajax 仅发送该表单的表单值。这就是我所拥有的。第一个表单按预期工作,第二个表单实际提交表单。如何单独定位每个表单。我觉得我应该在某处使用 .find() 。
<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>