【发布时间】:2015-09-28 18:54:47
【问题描述】:
通过移动设备运行的 ajax 代码会导致页面重新加载并且不执行插入(甚至不会提示错误消息),另一方面,一切都在计算机上正常运行,有什么想法吗?
$('#pending_request_submit').on("click",function() {
var url = "http://leagueofmusic.com/mobix-html/lib/pending_request.php"; // the script where you handle the form input.
$.ajax({
type: "POST",
url: url,
data: $("#pending_request").serialize(),
beforeSend: function(){
$('#request_response').html('<center><img src="css/img/loader.gif"></center>');
},
success: function(data)
{
$('#request_response').html(data); // show response from the php script.
}
});
return false; // avoid to execute the actual submit of the form.
});
【问题讨论】:
-
由于 javascript 错误,
return false没有发生的可能性更大。或者事件根本没有触发。由于页面重新加载,查看错误可能非常困难。 -
也有可能在移动设备上直接触发提交事件并跳过点击事件,从而绕过您的事件处理程序。
-
首先在表单中添加
action="javascript:alert('would have refreshed')"以阻止它在未正确阻止默认设置时刷新,这将允许您查看错误(如果有)。 -
实际上他把它弹出来了,仅此而已:p
-
那么我的另一种情况很可能是正确的:它根本没有触发点击事件。尝试使用提交事件。
标签: jquery ajax jquery-mobile