开发者

How do I stop Firefox from closing my streaming jQuery ajax response?

开发者 https://www.devze.com 2023-02-27 23:43 出处:网络
I\'m a little new to comet-esque requests, so please speak up if I\'m making too much work for myself and should be using a library or some other method.

I'm a little new to comet-esque requests, so please speak up if I'm making too much work for myself and should be using a library or some other method.

Basically this is my situation: I have a page that sets an <iframe> element's src attribute to a php script. The PHP script streams the response with the following headers:

Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: multipart/x-mixed-replace

This works famously in safari! However, firefox closes the connection after a couple of seconds. How do I fix this? I've examined the responses for the script for both browsers and the responses are identical otherwise (up to the point that Firefox closes the connection.)

Awesome update: Firefox hates the "Content-Type: multipart/x-mixed-replace". Once this is removed it works in Firefox.

Isn'开发者_如何转开发t there a better way to do this kind of thing?


The solution here is to send Content-Type: multipart/x-mixed-replace to Safari but not to Firefox.

For reasons I don't fully understand, Firefox will disconnect from the server after a few seconds if this header is present in the response. Firefox will handle a streaming response just fine otherwise.

To implement this, I simply added a check for the user agent in the code as such:


if( preg_match("/Safari/", $_SERVER["HTTP_USER_AGENT"]) )  
    header("Content-Type: multipart/x-mixed-replace");

0

精彩评论

暂无评论...
验证码 换一张
取 消