皆さん、私は現在、以下のコードを使用してページにAjaxサブミッションを実行しており、ユーザーデータのキャプチャに使用されているさまざまなメソッドを処理する方法が最も効果的かどうか疑問に思っていました。Ajaxサブミットメソッドの別の実行方法
より良い方法は何でしょうか?
これは私が現在使用しているJavaScriptコードです:
$(document).ready(function() {
$("#submit").click(function() {
$("#form").hide(300);
$.post('run.php', $("#form").serialize(),
function(data) {
$("#result").html(data);
});
return false;
});
});
は、これが私のフォームです:.post
<form id="booking">
<table width="600" cellpadding="2px" cellspacing="2px" style="font-size: 20px;">
<tr>
<th width="296" align="left">Date Of Wedding</th>
<td width="288"><input name='date' type='text' class='larger' id='date' value='' size='20'/></td>
</tr>
<tr>
<th align="left">Party Size</th>
<td><input name='partySize' type='text' class='larger' id='partySize' value='' size='20' /></td>
</tr>
<tr>
<th align="left">Catering Grade</th>
<td>1:
<input name='cateringGrade' type='radio' class='larger' value=1 size='12'/>
2:
<input name='cateringGrade' type='radio' class='larger' id='cateringGrade' value=2 size='12'/>
3:
<input name='cateringGrade' type='radio' class='larger' id='cateringGrade' value=3 size='12'/>
4:
<input name='cateringGrade' type='radio' class='larger' id='cateringGrade' value=4 size='12'/>
5:
<input name='cateringGrade' type='radio' class='larger' id='cateringGrade' value=5 size='12'/></td>
</tr>
<tr>
<th align="left"> </th>
<td> </td>
</tr>
<tr>
<th align="left"> </th>
<td><input name="submit" type="button" value="Submit" id="submit"/></td>
</tr>
</table>
</form>
dateType jsonを削除またはコメントアウトします。彼は明らかに返されたデータを、オブジェクト値ではなくhtmlとして使用しています。私はあなたがajax()のrequredデータを解析する場所を見つけることができません。 –
@ methusaleh。既に良い提案がありますが、 '$ .ajax.beforeSend()'と '$ .ajax.error()'メソッドも使用します。'$( '#form')。on( 'submit'、function(){...})'の場合、 "beforeSend"というフォームを非表示にすることができます。フォームに戻ることができます –