ajax div刷新

时间:2011-07-27 01:52:57

标签: ajax

我使用以下代码刷新div,但它不起作用请指导

<script src="moniter.js" type="text/javascript"></script>
<body onLoad="moniter();">
<div id="moniter">
<?php  echo rand() ;  ?>

      </div>
</body>

和js文件是

 var xmlHttp_moniter

    function moniter()
    {
        xmlHttp_moniter = GetXmlHttpObject_parcel()
        if(xmlHttp_moniter == null)
        {
            alert("browser does not support HTTP Request")
            return
        }
        var url="moniter.php?random=" + Maths.random()
        xmlHttp_moniter.onreadystatechange = stateChanged
        xmlHttp_moniter.open("GET",url,true)
        xmlHttp_moniter.send(null)

    }

    function stateChanged()
    {
        if(xmlHttp_moniter.readyState==4 || xmlHttp_moniter.readyState == "complete")
        {
            document.getElementById("moniter").innerHTML = xmlHttp_moniter.responseText
            setTimeout('moniter()',100);
        }
    }

    function GetXmlHttpObject_parcel()
    {
        var xmlHttp_moniter=null;
        try
        {
            xmlHttp_moniter=new XMLHttpRequest();
        }
        catch (e)
             {
                 //Internet Explorer
                 try
                  {
                      xmlHttp_moniter=new ActiveXObject("Msxml2.XMLHTTP");
                  }
                 catch (e)
                  {
                  xmlHttp_moniter=new ActiveXObject("Microsoft.XMLHTTP");
                  }
             }
        return xmlHttp_moniter;
    }

2 个答案:

答案 0 :(得分:4)

你有一个错字。尝试将Maths.random()替换为Math.random(),代码应按预期工作。

答案 1 :(得分:-1)

$('#urDivID').trigger('create');