开发者

how to be able to keep using a page(clickin,tasks etc..) while a javascript is still being loaded

开发者 https://www.devze.com 2023-02-13 00:54 出处:网络
i have designed a dashboard that auto refresh every 30 seconds. i am using jquery and so i we take the tab \"new users\" on the dasboard, it has a code like that:

i have designed a dashboard that auto refresh every 30 seconds.

i am using jquery and so i we take the tab "new users" on the dasboard, it has a code like that:

<li>New users Today: <span id="NbOfNewUsers">
  <script>refreshStatContent('Users')</script></span>开发者_C百科
</li>

now the script resfreshStatContent uses jquery $.ajax to get users content:

$.ajax({
   type: "GET",
   url: "usersctnt.php",
   dataType: "xml",
   success: function(xml)
   {
        }
       });

ok the problem is, even though ajax goes asynchronous, but still the fact that am using <script>refreshStatContent(\'Users\')</script> imposes that this javascript function finishes loading before i can do any task on the page. Right now if i try to click on a link on the page while the user content is loading, it doesn't let me... until the refreshStatContent(\'Users\') is finished...

is there a way to be able to still use the page even when a script is loading?

thanks a lot, much appreciated


instead of using you script like this:

<li>New users Today: <span id="NbOfNewUsers">
  <script>refreshStatContent('Users')</script></span>
</li>

you should include all of your javascript at the bottom of the page. Make a function that calls refreshStatContent on the span like this:

include jQuery

<script type="text/javascript">
     $(document).ready(function() {
       // do stuff when DOM is ready
       var usrList = efreshStatContent('Users');
       $(#NbOfNewUsers).append(usrList);       
     });
</script>
</body> 

Or you might even want to extract all of you js to an external file, so it is need and clean.

0

精彩评论

暂无评论...
验证码 换一张
取 消