大家好,我正在使用下面的代码在我的页面上运行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调用,如果有错误,你可以显示表格 –