繁体   English   中英

javascript window.setInterval无法在最新的Firefox和IE9上运行

[英]javascript window.setInterval not working on latest Firefox and IE9

我最近创建了一个自定义ping盒(聊天)以满足个人需求。 当我对其进行编码并在Firefox 3.6.13中进行测试时,它工作正常。 但是,与window.setInterval相关的功能在IE9或Firefox 6中似乎无法正常工作。

以下是javascript的代码。

    <script>

     function loadNewPosts(){
        var id = $(".altbgcolor:first").attr("id");

        $.get('/updateping.php', { updateid: id ,  }, function(data){
                                $(".newslist").prepend(data);
                            }, 'html');
     }

     window.setInterval(loadNewPosts, 1000*3)   


     $(document).ready(function() { 
    // bind form using ajaxForm 

             $("#pingForm").validate({


                submitHandler: function(form) {  
                $('#pingForm').ajaxSubmit({ 
                        // target identifies the element(s) to update with the server response 
                        target: '#pingResult', 

                        // success identifies the function to invoke when the server response 
                        // has been received; here we apply a fade-in effect to the new content 
                        success: function() { 

                            $('#msg').val('');
                            $('#pingResult').fadeIn('slow'); 
                            $('#pingResult').fadeOut(2000); 
                        } 
                    });
                }
            }); 

        })


 </script> 

以下是HTML

      <ul class="newslist" style="width:630px;">

        <li class="altbgcolor" id=64>
    <div>   
        <div class="newsthumb" style="width:50; height:50; "center center no-repeat;"><img src="images/personal/sunny.jpg" /></div>



        <div class="newstext" style="margin:0px;">


        <h1 style="color:#081C28;"><img width="11" height="9" src="/content/icon_topic_newest.gif">how r u?</h1>

        </div>
        <br /><br />
        <div style="font-size: 0.6em; color:#666666;">  
            <span style="text-decoration:none; color:none; padding:5px;"><i> from: <a href="" style="text-decoration: none;color:#105289 ;" onmouseover="this.style.textDecoration = 'underline'" onmouseout="this.style.textDecoration = 'none'">Sunny</a></i></span>                          
            <span style="text-decoration:none; color:none; padding:5px; "><i> posted: <a href="" style="text-decoration: none;color:#105289 ;" onmouseover="this.style.textDecoration = 'underline'" onmouseout="this.style.textDecoration = 'none'">October 29, 2011, 9:58 am</a></i></span>                           
        </div>  

        <div class="clear"></div>
     </div>


    </li>
        </ul>

我尝试使用Firebug调试问题,但是尽管window.setInterval似乎能够每隔3秒调用带有所需参数的.php文件,但是它并未显示php文件的o / p。

php代码(updateping.php)

        <?

        require_once('includes/connection.php');
        require_once('includes/functions.php');

        if(isset($_GET['updateid']))
        {
            $updateid=$_GET['updateid'];
            $sql="SELECT * FROM ping WHERE id > $updateid ORDER BY id DESC";

            $res=mysql_query($sql,$connection);

            if(@mysql_num_rows($res))
            {
                while($data=mysql_fetch_array($res))
                        //while($data=mysql_fetch_array($result))
                        {
                                echo '<li class="altbgcolor" id='.$data['id'].'>
                                    <div>   
                                        <div class="newsthumb" style="width:50; height:50; center center no-repeat;"><img src="'.$data['img'].'"  /></div>



                                        <div class="newstext" style="margin:0px;">


                                        <h1 style="color:#081C28;"><img width="11" height="9" src="/content/icon_topic_newest.gif">'.stripslashes($data['msg']).'</h1>

                                        </div>
                                        <br /><br />
                                        <div style="font-size: 0.6em; color:#666666;">  
                                            <span style="text-decoration:none; color:none; padding:5px;"><i> from: <a href="" style="text-decoration: none;color:#105289 ;" onmouseover="this.style.textDecoration = \'underline\'" onmouseout="this.style.textDecoration = \'none\'">'.$data['name'].'</a></i></span>                          
                                            <span style="text-decoration:none; color:none; padding:5px; "><i> posted: <a href="" style="text-decoration: none;color:#105289 ;" onmouseover="this.style.textDecoration = \'underline\'" onmouseout="this.style.textDecoration = \'none\'">'.$data['entry_date'].'</a></i></span>                         
                                        </div>  
                                        <div class="clear"></div>
                                     </div>


                                    </li>'; 


                        }


            }

        }




        ?>

我在这里修复,不明白可能是什么问题。 该聊天框在FF 3.6.13上正常运行

请帮我一个人!!!!!!!!!!!

更新:我尝试使用IE9'F12'开发人员调试器,发现每3秒钟就认为php文件称为返回结果类型304-未修改。 :((

我转到调试器菜单上的“缓存”选项,并选中了“始终从服务器刷新”选项和bammmm! 它现在工作了。

任何想法如何在实际的IE和Firefox设置中进行调整。 该问题似乎仅与缓存有关。

由于您已经在使用jQuery,因此可以尝试以下操作:

$(document).ready(function() {
  $.ajaxSetup({ cache: false });
});

按照jQuery .ajax doco,jQuery会自动将时间戳添加到您的请求中,以使浏览器不会尝试将缓存用于后续请求。

或者,您可以尝试使用HTTP响应标头的“缓存控制”部分中的设置来修复服务器端的缓存问题,但是我不知道如何在PHP中做到这一点。

在您的get请求中添加时间戳,或者改用post。

$.get('/updateping.php', { updateid: id , time: new Date().valueOf() }, function(data){
    ...

要么

$.post('/updateping.php', { updateid: id }, function(data){
    ...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM