jQuery的卸载与AJAX调用不工作在Chrome浏览器 [英] jQuery unload with an AJAX call not working in Chrome

查看:117
本文介绍了jQuery的卸载与AJAX调用不工作在Chrome浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我最简单的code片断:

This is my very simple code snippet:

$(window).unload(function() {
        $.ajax({
            url: 'stats_pages.php?last_id='+$("#last_id").val(),
        });
});

就这么简单。 Ajax调用被称为完美的Firefox,但无法在Chrome。我试过其他的变化,哪种类型的工作:

Simple enough. The AJAX call gets called perfectly in Firefox, but fails in Chrome. I've tried other variations, which sort of work:

window.onbeforeunload = function(){
        $.ajax({
            url: 'stats_pages.php?last_id='+$("#last_id").val(),
        });
        return false;
}

这工作在Chrome浏览器,但它提醒假与通常的你要离开这个页面你确定?消息,这不是我想要的效果显着。如果没有返回false; ,它不火的AJAX调用

This works in Chrome, but it alerts "false" with the usual "Are you sure you want to leave this page?" message, which is not what I want obviously. Without the return false;, it doesn't fire the AJAX call.

在理想情况下,我喜欢的第一个解决方案是最好的,但没有任何人知道这是怎么回事?

Ideally I like the first solution the best, but does anybody know what's going on?

推荐答案

设置异步:假的在你的Ajax调用

Set ASYNC : false in your ajax call

$(window).unload(function() {
        $.ajax({
            url: 'stats_pages.php?last_id='+$("#last_id").val(),
            async : false,
        });
});

这篇关于jQuery的卸载与AJAX调用不工作在Chrome浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆