【发布时间】:2012-08-24 10:58:32
【问题描述】:
我有这个 iOS 网络应用程序,它需要通过 Ajax 提交表单,这在大多数情况下都有效。 唯一不起作用的是键盘上的 GO 按钮没有响应。
在桌面浏览器上,一切正常提交(提交按钮,或输入键)
在 Safari iOS 上,一切正常(提交按钮、GO 键盘按钮)
但是在 iOS 上作为 Web App 使用时,GO 按钮不起作用!
什么可能导致这种行为?据我所知,iOS 网络应用程序仍在使用 Safari... :)
<form id="myForm" name="form" action="link-to-script.php" method="post">
<table>
<tr>
<td><input id="name" name="name" type="text" size="20" maxlength="25" /></td>
</tr>
<tr>
<td><input id="email" name="email" type="text" size="20" maxlength="50" /></td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Send" /></td>
</tr>
</table>
$('#myForm').submit(function(e) {
e.preventDefault(); // Doesn't matter
var dataString = $(this).serialize();
$.ajax({
type: "POST",
url: "http://link-to-script.php?", // Valid link for the use of this form
cache: false,
data: dataString,
success: function() {
}
});
});
更新(已解决):我再次删除了preventDefault()。它并没有成为我的瓶颈,但我不喜欢不必要的代码。 :)
当我在$('#myForm').submit(function() { 的底部添加return false; 时,一切正常。
iOS GO 按钮、Enter 和 Submit 按钮现在都响应了。
【问题讨论】:
标签: jquery ajax jquery-ui ios5 iphone-web-app