jQuery的阿贾克斯()不会在Safari工作时,​​它需要几秒钟得到返回的数据 [英] jQuery .ajax() does not work in Safari when it takes seconds to get returned data

查看:255
本文介绍了jQuery的阿贾克斯()不会在Safari工作时,​​它需要几秒钟得到返回的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jQuery的阿贾克斯()方法来传递(GET)数据到另一个ExportData页面,并获得返回的数据(成功/失败),该页面后工序。该ExportData页面大约需要10秒钟,然后返回成功/失败。

I'm using the jQuery ajax() method to pass on (GET) data to another ExportData page, and get the returned data ("succeeded/failed") after that page processes. The ExportData page takes about 10 seconds before it returns "succeeded/failed".

在code我使用的作品以及在其他浏览器(FF / IE / Chrome浏览器),但不是在Safari浏览器。在Safari中的code督察状态code表示的是-1001,并没有收到任何数据。虽然还有一些其他的ajax()请求(不需要,只要把这个页面返回的数据),他们做的工作(与200状态)。

The code I'm using works well in other browsers (FF/IE/Chrome) but NOT in Safari. In Safari's code inspector the status code showed is -1001 and no data was received. Whilst there're other ajax() requests (not need so long as this page to return data) and they do work (with status of 200).

我有这样的发送和接收数据之间的间隔较长,会导致错误的Safari猜测。不过,我也发现了-1001错误很快表明,这可能意味着没有执行ExportData.php。

I had a guess that the long interval between sending and receiving data causes error for Safari. However I also found the -1001 error shows very quickly, that might means the ExportData.php was not executed.

有没有人有这个问题的想法?您的帮助将大大AP preciated!

Does anyone have an idea about this issue? Your help will be greatly appreciated!

在code是:

ExportData: function (date,view) {
    ajaxcall.data = {};
    ajaxcall.url = 'ExportData.php?Date='+date+'&View='+view;
    ajaxcall.callbackfunction = UserEvents.ExportSuccess;
    ajaxcall.Call();
},

在AjaxCall的在另外的文件:

The "ajaxcall" is in another file:

var ajaxcall = {
    SitePath: '',
    data: '',
    url: '',
    callbackfunction: '',
    fileElementClass: '',
    AjaxRequest: false,
    callback: true,
    Call: function () {
        if (ajaxcall.AjaxRequest == true) {
            alert(ajaxcall.AjaxRequest);
            return;
        }
        else {
            try {
                ajaxcall.AjaxRequest == true;
                $.ajax({
                    type: "GET", 
                    url: ajaxcall.url,
                    data: ajaxcall.data,
                    dataType: "json",
                    async: false,
                    success: function (data) {
                            if (ajaxcall.callback == true) {
                                ajaxcall.callbackfunction(data);
                            }
                    },
                    error: function (request, status, error) {},
                    complete: function () {
                        ajaxcall.AjaxRequest = false;
                    }
                });
            }
            catch (e) {
                ajaxcall.AjaxRequest == false;
            }
        }
    },
};

谢谢,刘松涛

Thanks, Sean Liu

推荐答案

这是一个老问题,我不知道你是否已经找到了答案,但我们最近遇到了同样的问题。大量的研究和测试后,我们发现,Safari浏览器会忽略超时设置为同步AJAX调用,限制为10秒。我想这被认为是一个用户体验的事情,因为同步调用会使页面似乎挂起,他们可能认为这样做对的很长一段时间或者是不是用户友好的或无响应的页面。

This is an old question, and I'm not sure if you have found the answer, but we recently ran into this same issue. After a lot of research and testing, we found out that Safari ignores timeout settings for Synchronous AJAX calls, limiting to 10 seconds. I guess this is considered a user experience thing, as synchronous calls will make the page appear to hang, and they may assume that doing so for a long period of time is either not user friendly or an unresponsive page.

所以,你基本上有两种选择,你可以修改你的code使用的输出缓冲器定期发回数据。这将触发Safari浏览器认识到,要求至少是积极响应,并且通常不会迫使它超时。我们从来没有试过,所以我不能保证,但我在这里看到有不同的一些成功的案例。另一种选择是,只是改变了AJAX调用是异步的。这可能是更容易的方法,但您可能需要实现一些承诺,模拟同步响应,如果您的应用程序依赖于具有同步调用。

So you basically have two options, you can either modify your code to use an output buffer to periodically send data back. This should trigger Safari to recognize that the request is at least active and responding, and usually won't force it to time out. We never tried this, so I can't vouch for it, but I have seen some stories of varying success here and there. The other option is to just change the AJAX call to be asynchronous. This is probably the easier method, but you may need to implement some promises to "simulate" a synchronous response if your application depends on having a synchronous call.

有关参考,这里就是我们开始了在追查问题:的 HTTP:??//proper$c$c.com/word$p$pss/ P = 32

For reference, here's where we got started on tracking down the issue: http://propercode.com/wordpress/?p=32.

这篇关于jQuery的阿贾克斯()不会在Safari工作时,​​它需要几秒钟得到返回的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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