简体   繁体   English

jQuery .load缓慢加载页面

[英]Jquery .load loads page slowly

I am using this code: 我正在使用此代码:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">// <![CDATA[
$(document).ready(function() {
$.ajaxSetup({ cache: false }); // This part addresses an IE bug. without it, IE will only load the first number and will never refresh
setInterval(function() {
$('.container').load('dashboard.php');
}, 10000); // the "3000" here refers to the time to refresh the div. it is in milliseconds.
});
// ]]></script>

<div class="container"><h3>Loading Dashboard...</h3></div>

to reload a webpage every X Seconds but on the first load it seems to take a while to load/display 每X秒重新加载一次网页,但第一次加载似乎需要一段时间才能加载/显示

if i type the page name in the address bar (domain.com/dashboard.php) it loads instantly 如果我在地址栏中输入页面名称(domain.com/dashboard.php),则会立即加载

is there any way to make it load quicker? 有什么方法可以使其加载更快?

setInterval waits for the defined number of milliseconds before it calls the function for the first time. setInterval等待定义的毫秒数后才首次调用该函数。 So either set the content of .container on the server side (using php) instead of 'Loading Dashboard...' or load the content on page load: 因此,要么在服务器端(使用php)设置.container的内容,而不是“ Loading Dashboard ...”,要么在页面加载时加载内容:

function reloadContainer() {
    $('.container').load('dashboard.php');
}
setInterval(reloadContainer, 10000);

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM