[英]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.