index.php....
<?phpfor (){
    echo '<script>var myuin=new Array();</script>';
    echo '<script>myuin['.$i.']='.$uin.';</script>';
?>
......
<?php    <div id = cr_<?php echo uin; ?>></div>}?>
......这样定义JS数组是正确的,或许有点傻瓜式.以上是index.php与上面的js有关的部份代码

解决方案 »

  1.   

    你ajax 返回结果需要一定的时间,这个时候你早已经循环完了,所以没有结果
      

  2.   

    我是想到过这一点,但AJAX并不了解,请问什么好的办法解决吗?总不可能每次加个alert吧,呵呵.
      

  3.   

    我觉得问题是:你总是用一个xmlhttp对象去请求,在循环里,每循环一次,xmlhttp就变化了,上一个请求无法返回.你试着把创建xmlhttp对象的语句包装成函数,每次产生一个新的请求对象.eval("cr_" + myuin[i]) 这个已经不能用了.function changeselect(locationid)
    {
      if (locationid == null) return;
        var url = "ajax_chatroom.php?uin=" + escape(locationid);
        // alert(url);在此加入这句所有显示均正常正确
        xmlHttp.open("GET", url, true);
        xmlHttp.onreadystatechange = function(){ resultValue(locationid);};
        xmlHttp.send(null); 
    }function resultValue(id)
    {
      if (xmlHttp.readyState == 4 && xmlHttp.status == 200) 
      {
        document.getElementById(id).innerHTML = xmlHttp.responseText;
      }
    }
      

  4.   

    呵呵,我把代码改成这样了:<script language="javascript">function f_xmlHttp()
    {
    var xmlHttp = false;
    try
    {
    xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
    try
        {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    catch (e2)
    {
    xmlHttp = false;
    }
    } if (!xmlHttp && typeof XMLHttpRequest != 'undefined')
    {
    xmlHttp = new XMLHttpRequest();
    }
    return xmlHttp;
    } for (var i = 0; i < myuin.length; i++)
    {
    changeselect(myuin[i]);
    }function changeselect(locationid)
    {
        if (locationid == null) return;
        var url = "ajax_chatroom.php?uin=" + escape(locationid);
    xmlHttp = f_xmlHttp();
        xmlHttp.open("GET", url, true);
        xmlHttp.onreadystatechange = function(){ resultValue(locationid);};
        xmlHttp.send(null); 
    }function resultValue(locationid)
    {
    if (xmlHttp.readyState == 4 && xmlHttp.status == 200) 
        {
    document.getElementById(locationid).innerHTML = xmlHttp.responseText;
        }
    }</script>
      

  5.   

    var xmlHttp = f_xmlHttp();放到代码最前面
    <script language="javascript">function f_xmlHttp()
    {
    var xmlHttp = false;
    try
    {
    xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
    try
    {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e2)
    {
    xmlHttp = false;
    }
    }if (!xmlHttp && typeof XMLHttpRequest != 'undefined')
    {
    xmlHttp = new XMLHttpRequest();
    }
    return xmlHttp;
    }for (var i = 0; i < myuin.length; i++)
    {
    changeselect(myuin[i]);
    }function changeselect(locationid)
    {
    if (locationid == null) return;
    var url = "ajax_chatroom.php?uin=" + escape(locationid);
    xmlHttp.open("GET", url, true);
    xmlHttp.onreadystatechange = function(){ resultValue(locationid);};
    xmlHttp.send(null);
    }function resultValue(locationid)
    {
    if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
    {
    document.getElementById(locationid).innerHTML = xmlHttp.responseText;
    }
    }</script>
      

  6.   

    放到最前面不行的,现在的效果可看下:http://211.95.72.126,打开后直接点"视频搜索",看会员的房间状态图片,第一次执行只有最后一个会员的图片显示的出来,然后比如将页面刷新一下,才能全部出来
      

  7.   

    我这里没有什么问题啊,所有的图片都可以显示出来可以看到房间未开放或者进入我的直播室的图片.
    如果你那里还是不行,清一下cache试试