长轮询的jQuery不会在IE浏览器 [英] Long polling jQuery doesn't work in IE

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

问题描述

$。阿贾克斯似乎在IE浏览器无法正常工作。我应该怎么做,或者它只是一个错误,在IE浏览器?我是否需要提供我的code在这里得到帮助?因为现在看来,这不与任何$阿贾克斯例如工作。

我的code:

 函数的get_info(线){
    $阿贾克斯({
        键入:POST,
        缓存:假的,
        网址:chat.php RandomNumber =?+的Math.random()
        数据:TYPE =的get_info和放大器;线=+行+&放大器; RandomNumber =+的Math.random()
        数据类型:JSON,
        成功:函数(MSG){
          线= msg.lines;

          如果(msg.new_messages)
          {
            对于(i = 0; I< msg.messages.length;我++)
            {
                $('。聊天')追加。(&其中; P>中+ msg.messages [I] +&所述; / P>中);
            }
            的document.getElementById('健谈')scrollTop的=的document.getElementById('健谈')scrollHeight属性。;
          }
        },
        完成:函数(){
            的setTimeout(的get_info,1000线);
        }
    })

};

的setTimeout(的get_info,1000,0);
 

解决方案

我现在看到你使用的setTimeout 的形式,不与IE <工作SUP> <一个href="http://www.makemineatriple.com/2007/10/passing-parameters-to-a-function-called-with-settimeout"相对=nofollow> 1 <强> 2

 的setTimeout(myFunction的,myTimeout,参数); //为IE浏览器不工作
 

相反,使用匿名函数作为其应该调用预期的功能与正确的论点论据:

 的setTimeout(函数(){myFunction的(myParameter);},myTimeout);
 

所以,你到的setTimeout 初始呼叫应改为:

 的setTimeout(函数(){的get_info(0);},1000);
 

成功的后续调用应该是:

 的setTimeout(函数(){的get_info(线);},1000);
 


如果这是因为IE浏览器缓存的GET请求,你可以简单地设置缓存 jQuery.ajax(),让jQuery的为您处理它(记得要清除进行此更改后缓存):

  //做到这一点的*所有* Ajax请求
$ .ajaxSetup({
    缓存:假的
});
 

  //做这个ajax请求
$阿贾克斯({
    缓存:假的,
    这里//..other选项
});
 

$.ajax seems to not work in IE. What should I do or it's just another bug in IE? Do I need to provide my code here to receive help? Because it seems it doesn't work with any $.ajax example.

My code:

function get_info(lines) {
    $.ajax({
        type: "POST",
        cache: false,
        url:  "chat.php?RandomNumber=" + Math.random(),
        data: "type=get_info&lines="+lines+"&RandomNumber=" + Math.random(),
        dataType: "json",
        success: function(msg){
          lines = msg.lines;

          if(msg.new_messages)
          {
            for(i = 0; i < msg.messages.length; i++)
            {
                $('.chat').append("<p>"+msg.messages[i]+"</p>");      
            }
            document.getElementById('chatty').scrollTop = document.getElementById('chatty').scrollHeight;
          }
        },
        complete: function() {
            setTimeout(get_info, 1000, lines); 
        }
    })    

};    

setTimeout(get_info, 1000, 0); 

解决方案

I now see that you're using a form of setTimeout that doesn't work with IE1, 2:

setTimeout(myFunction,myTimeout,parameter); //does NOT work for IE

Instead, use an anonymous function as the argument which should call the intended function with the correct argument:

setTimeout(function(){myFunction(myParameter);},myTimeout);

So your initial call to setTimeout should be changed to:

setTimeout(function(){get_info(0);}, 1000); 

and subsequent calls on success should be:

setTimeout(function(){get_info(lines);}, 1000); 


If this is because IE is caching your GET requests, you could simply set cache to false for jQuery.ajax() and let jQuery handle it for you (remember to clear your cache after making this change):

//do this for *all* ajax requests
$.ajaxSetup ({
    cache: false
});

or

//do it for this ajax request
$.ajax ({
    cache: false,
    //..other options here
});

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

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