AJAX长轮询不工作与IE浏览器 [英] AJAX long polling not working with IE

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

问题描述

我似乎有长轮询和IE浏览器的一个问题。这是我第一次涉足长轮询,所以我成立了一个简单的测试,看看我是否可以使它发挥作用。这似乎表现得蛮好用FF和铬,但我得到不同的结果与IE浏览器。

I seem to be having a problem with long polling and IE. This is my first foray into long polling, so I set up a simple test to see if I could make it work. It seems to behave just fine with FF and Chrome, but I'm getting different results with IE.

首先,这里的一些code:

First, here's some code:

HTML / JavaScript的:

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.9.2.min.js"></script>
<script type="text/javascript">
//<![CDATA[
$(document).ready(function()
{
    (function poll()
    {
        $.ajax({
            url: 'events/alert-data.php',
            success: function (e)
            {
                $('#results').append($('<div>Success: ' + e.text + '</div>').fadeIn(1000));
            },
            error: function (e)
            {
                console.log(e);
            },
            dataType: 'json',
            complete: poll,
            timeout: 10000
        });
    })();
});
//]]>
</script>
</head>

<body>
<div id="results">hello</div>
</body>
</html>

PHP:

<?php

$time = time();

while (time() - $time < 5) { }

echo json_encode(array('text' => time()));

?>

在FF / Chrome浏览器,我看到期望的数据:

In FF/Chrome, I'm seeing expected data:

hello
Success: 1356104196
Success: 1356104201
Success: 1356104217
Success: 1356104222
Success: 1356104227

不过,在IE它重复了第一个成功行无限。至少我presume是无限的,因为它锁定了浏览器,不会允许我以滚动。

But in IE it repeats the first Success line infinitely. At least I presume it's infinite as it locks up the browser and won't allow me to scroll.

我不知道我在做什么错。任何帮助将是非常美联社preciated。

I'm not sure what I'm doing wrong. Any help would be much appreciated.

在此先感谢。

推荐答案

与IE浏览器的问题似乎是缓存的结果,可能是IE浏览器本身。这可能发生在任何浏览器。

The problem with IE would appear to be the consequence of caching, probably by IE itself. This could potentially happen in any browser.

尝试增加:

cache: false 

到AJAX选项。

to the ajax options.

这篇关于AJAX长轮询不工作与IE浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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