AJAX实现loading….效果

<script type="text/javascript">

var xmlHttp;

//创建一个xmlHttpRequest对象

function createXMLHttpRequest() {

    if (window.ActiveXObject) {

        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");

    }

    else if (window.XMLHttpRequest) {

        xmlHttp = new XMLHttpRequest();

    }

}

function handleStateChange(){

       var img = "<img src='/images/green/loading.gif' style='margin-top:130px; margin-left:250px'>";

    if(xmlHttp.readystate == 4){   //表示请求状态 4为完成

           if(xmlHttp.status == 200){ //http状态指示码,200表示ok

                     //将服务器返回信息作为文本插入到DIV容器中。

               document.getElementById("data").innerHTML = xmlHttp.responseText;

          }

    }

else document.getElementById("data").innerHTML = img;

//若响应未完成的话,则显示loading..

}

       function showData(entityName){

         var url = "/greengate.action?doing=listResult&entity_name="+entityName;

      createXMLHttpRequest();

         //请求状态改变事件触发handleStateChange功能

      xmlHttp.onreadystatechange = handleStateChange;

        xmlHttp.open("GET",url);

      xmlHttp.send(null);    

       }

</script>

 

你可能感兴趣的:(Ajax,function,服务器,null,url,XMLhttpREquest)