问 题
我似乎有长轮询和IE浏览器的一个问题。这是我第一次涉足长轮询,所以我成立了一个简单的测试,看看我是否可以使它发挥作用。这似乎表现得蛮好用FF和铬,但我得到不同的结果与IE浏览器。
首先,这里的一些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浏览器,我期望看到的数据:hello Success: 1356104196 Success: 1356104201 Success: 1356104217 Success: 1356104222 Success: 1356104227
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.
I'm not sure what I'm doing wrong. Any help would be much appreciated.
Thanks in advance.
解决方案
与IE浏览器的问题似乎是缓存的结果,可能是IE浏览器本身。这可能发生在任何浏览器。
尝试增加:
cache: false到AJAX选项里面。