如何加载单独的事业部无负载整个页面,并显示加载状态?加载、负载、事业部、状态

2023-09-10 17:06:49 作者:- 自我封锁。

我怎么能单独加载单独的事业部,而不会影响该div PHP和MySQL或Ajax和SQL当前页面并显示加载状态

How can I load individual Div separately without affecting current page and show loading status for that div with PHP and MySQL or Ajax and SQL

推荐答案

我这样做:

首先你的隐藏分区的加载,如果它和负载按钮:

first you have the hidden div with a loading if in it and a load button:

<div id="displayDiv" style="display: none">
  <img id="loadingGif" src="loadingGif" style="display:none"; />
  <div id="actualContent" style="display:none" />
</div>
<input type="button" id="loadButton" />

然后你有JS code(使用jQuery)

Then you have the JS code ( I use jQuery )

<script type="text/javascript">
   $(document).ready( onDocumentReady); // this runs before page load

   function onDocumentReady()
   {
      $('#loadButton').click( onLoadClick ); //assign action on button click
   }   

   function onLoadClick()
   {
       $('#loadingGif').show(); // show the loading gif. It won't show as long as it's parent is hidden
       $('#actualContent').hide(); // hide the actual content of the response;
       $('#displayDiv').show(); // display the div
       $.get("test.php", onRequestComplete ); // make the ajax request to the stand alone PHP file
      //so as long as the content loads, the loading gif will show;
   }

   function onRequestComplete( data )
   {
      $('#loadingGif').hide();
      $('#actualContent').html( data );
      $('#actualContent').show();
   }
</script>

所以。你有一个容器displayDiv;里面你有一个形象loadingGIf和另一个容器actualContent;当您单击Load按钮,大容器装载GIF出现,通知的东西是加载用户。当内容被加载,你只是隐藏loadingGif,并显示在actualContentGIF的信息。在test.php的,你只是附和必​​须出现在股利。我推荐使用JSON,但你会阅读更多关于它。

So. You have a container "displayDiv"; inside you have an image "loadingGIf" and another container "actualContent"; When you click the load button, the big container with the loading gif appears, notifying the user that something is loading. When the content is loaded, you just hide the loadingGif, and display the info in the "actualContent" gif. In the test.php you just echo what must appear in the div. I recommend using JSON, but you'll read more about it.

希望这有助于。