changing visibility using javascript

后端 未结 3 1193
时光取名叫无心
时光取名叫无心 2020-12-09 16:43

hi i have web page which uses ajax to retrieving data from another pages and while doing that i want to show a loading gif in the page so i\'ve create a div with my gif on i

3条回答
  •  醉梦人生
    2020-12-09 17:22

    function loadpage (page_request, containerid)
    {
      var loading = document.getElementById ( "loading" ) ;
    
      // when connecting to server
      if ( page_request.readyState == 1 )
          loading.style.visibility = "visible" ;
    
      // when loaded successfully
      if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
      {
          document.getElementById(containerid).innerHTML=page_request.responseText ;
          loading.style.visibility = "hidden" ;
      }
    }
    

提交回复
热议问题