jQuery .ajax() does not work in Safari when it takes seconds to get returned data

后端 未结 2 1924
花落未央
花落未央 2021-02-10 09:40

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

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-10 10:15

    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.

    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.

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

提交回复
热议问题