【问题标题】:Ajax request causes the page to reload - on mobile phoneAjax 请求导致页面重新加载 - 在手机上
【发布时间】: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


【解决方案1】:

很可能无论移动设备使用什么提交表单都是直接提交表单,而不是单击提交按钮。在这种情况下,使用提交事件将修复它:

$('#pending_request_form').on('submit',function() {

【讨论】:

    猜你喜欢
    • 2016-04-20
    • 2012-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-06
    相关资源
    最近更新 更多