$.post 调用在 safari 中没有发生 [英] $.post call is not happening in safari

查看:34
本文介绍了$.post 调用在 safari 中没有发生的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了奇怪的问题.关闭完整的 safari 浏览器时,我需要使用 jquery post 调用一个函数.但这在关闭 safari 浏览器时不会调用.但是美在所有其他浏览器中都有效.

I am facing strange issue. when closing complete safari browser, I need to call one function using jquery post. but this is not calling when close safari browser. But beauty is working in all other browser.

下面是我的一段代码,

<script language="JavaScript">
window.onbeforeunload = confirmExit;
function confirmExit()
{
   $.post("test.php");
}
</script>

请在 safari 中完成这项工作.

Please kindly get this work in safari.

谢谢,迪内什·库马尔·马诺哈兰

Thanks, Dinesh Kumar Manoharan

推荐答案

这可能是因为您正在执行异步发布,而 Safari 在发出请求之前停止运行 JavaScript(由于页面被卸载).尝试使用 $.ajax 而不是 $.post 并将 async 设置为 false.类似(未经测试):

This may be because you are doing an asynchronous post, and Safari stops running the JavaScript (due to the page being unloaded) before it issues the request. Try making the call blocking by using $.ajax instead of $.post and setting async to false. Something like (untested):

function confirmExit() {
    $.ajax({
        'async': false,
        'type': 'POST',
        'url': 'test.php'
    });
}

这篇关于$.post 调用在 safari 中没有发生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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