【问题标题】:Can't get jQuery AJAX to work on the unload tried EVERY post and still nothing无法让 jQuery AJAX 处理卸载尝试了每个帖子,但仍然一无所获
【发布时间】:2014-01-06 17:41:29
【问题描述】:

这是不工作的代码

        $( window ).bind("beforeunload",function () {
            $.ajax({
                type: 'POST',
                async: false,
                url: "dir",
                data: {REMID: "<?LOGPOSTID?>"}
            }).done(function(msg){alert(msg)});
            $.ajax({
                type: 'POST',
                async: false,
                url: "dir",
                data: {REMID: "<?LOGPOSTID?>"}
            });
        });

第一个 ajax 末尾的“完成”功能没有出现,我不确定它哪里出错了

【问题讨论】:

    标签: jquery ajax post asynchronous


    【解决方案1】:

    任何绑定到beforeunload 事件的 AJAX 请求都不能保证在页面卸载之前发出。一旦页面开始卸载,AJAX 将被取消。

    如果相同的代码在 click 事件处理程序中有效但在此处无效,这可能就是原因。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多