简体   繁体   English

如何在仍加载JavaScript的情况下继续使用页面(点击,任务等)

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

i have designed a dashboard that auto refresh every 30 seconds. 我设计了一个仪表板,该仪表板每30秒自动刷新一次。

i am using jquery and so i we take the tab "new users" on the dasboard, it has a code like that: 我正在使用jquery,所以我在dasboard上使用“新用户”标签,它具有如下代码:

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

now the script resfreshStatContent uses jquery $.ajax to get users content: 现在,脚本resfreshStatContent使用jquery $ .ajax获取用户内容:

$.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. 好的问题是,即使ajax异步了,但使用<script>refreshStatContent(\\'Users\\')</script>的事实仍然表明,此javascript函数必须先完成加载,然后我才能在页面上执行任何任务。 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... 现在,如果我尝试在加载用户内容时单击页面上的链接,它不会让我...直到refreshStatContent(\\'Users\\')完成...

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. 您应该在页面底部包含所有JavaScript。 Make a function that calls refreshStatContent on the span like this: 制作一个在跨度上调用refreshStatContent的函数,如下所示:

include jQuery 包括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. 或者,您甚至可能希望将所有js提取到一个外部文件中,因此这是必要且干净的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用javascript在<form>标签内附加<asp:Button />等.. - How to append <asp:Button /> etc.. within the <form> tag using javascript? 放大元素,同时仍然能够浏览页面 - Zoom in on an element while still being able to navigate page 如何使用 PHP / CURL / Javascript 等从 mca.gov.in 获取公司详细信息? - how to get company details from mca.gov.in using PHP / CURL / Javascript etc..? 如何在 Javascript 中使用循环(forEach、map 等)将数组转换为对象 - How to convert array to object using loop (forEach, map, etc..) in Javascript 如何在仍然能够下载其内容的同时阻止元素跳转到新页面? - How to stop a element from jumping to new page while still being able to download its content? 如何在加载页面时创建弹出窗口? - How to create a popup while a page is being loaded? 如何使用触发器等在准备就绪的文档上初始化我的功能? - how to initialize my function on document ready using trigger etc..? 使用 jquery/javascript:如何在无法编辑 html 的情况下删除空格并保持中断 - Using jquery/javascript: How to remove whitespaces and keep breaks without being able to edit the html Javascript 自动滚动 div 内容,同时仍然可以手动滚动 - Javascript auto scroll div content while still being able to manually scroll 如果用户中止连接到服务器(连接时刷新,关闭浏览器等),如何停止执行所有功能(多个异步等)。 - How to stop all functions (multiple asyncs etc) from executing if user abort connecting to the server (refresh while connecting, close browser, etc..)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM