我正在使用Ajax使用Twitter Bootstrap选项卡加载div中另一个页面的内容,但是ajax加载页面的时间太长.
没有Ajax页面加载速度非常快!
在ajax调用中加载的页面:28.743376016617 ms
页面加载没有ajax:0.00022506713867188毫秒
$(function() {
$("#MainTabs").tab();
$("#MainTabs").bind("show", function(e) {
var contentID = $(e.target).attr("data-target");
var contentURL = $(e.target).attr("href");
if (typeof(contentURL) != 'undefined')
$(contentID).html('<img src="<?PHP echo IMG_DIR; ?>loading/loading-large.gif" width="64" />').load(contentURL, function(){
$("#MainTabs").tab();
});
else
$(contentID).tab('show');
});
$('#MainTabs a:first').tab("show");
});
<?PHP
$start = microtime(TRUE); // Start counting
ob_start();
session_start();
$temp = microtime(TRUE) - $start;
echo $temp;
exit;
/*
* Here is the rest of the contents of the script, so I gave the 'exit' and even with the exit delay it that way!
*/
有谁知道发生了什么以及如何帮助我?
PHP代码非常简单,耗时太长!
谢谢!
解决方法:
您的Ajax是否从后端加载了需要时间来生成html的html?
如果没有Ajax,您可以加载更少的数据,这样它的运行速度就会快.
如果加载的数据不常见,则通过异步脚本加载.在页面加载后几秒钟加载ajax div.
>如果需要很长时间加载,请取消ajax请求.
$(document).ready(
var xhr;
var fn = function(){
if(xhr && xhr.readyState != 4){
xhr.abort();
}
xhr = $.ajax({
url: 'ajax/progress.ftl',
success: function(data) {
//do something
}
});
};
var interval = setInterval(fn, 500);
);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。