ページに複数のフォームがあります。フォームの送信ボタンをクリックすると、そのフォームのみのフォーム値をajax経由で送信したい。これが私が持っているものです。最初のフォームは想定どおりに機能し、2 番目のフォームは実際にフォームを送信します。各フォームを個別にターゲットにするにはどうすればよいですか。どこかで .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>