大家好,我正在使用下面的代碼在我的頁面上運行ajax提交,並且懷疑它是否是處理它的最有效的方式,因爲用於捕獲用戶數據的各種方法。運行ajax提交方法的其他方法
更好的方法需要什麼?
這是JavaScript代碼我目前使用:
$(document).ready(function() {
$("#submit").click(function() {
$("#form").hide(300);
$.post('run.php', $("#form").serialize(),
function(data) {
$("#result").html(data);
});
return false;
});
});
這是我的形式:
<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()的請求數據的位置。 –
@methusaleh。您已經有了一些很好的建議,但我也會使用'.ajax.beforeSend()'&'$ .ajax.error()'方法。 (''form')。on('submit',function(){...})'你可以隱藏表單「beforeSend」 - 對ajax調用,如果有錯誤,你可以顯示錶格 –