【发布时间】:2013-12-14 11:48:06
【问题描述】:
我正在使用 Ajax 通过 Twitter Bootstrap 选项卡在 div 中加载另一个页面的内容,但是 ajax 加载页面的时间过长。
没有 Ajax 页面加载速度非常快!
在 ajax 调用中加载的页面:28.743376016617 毫秒
页面加载时没有 ajax:0.00022506713867188 ms
这是ajax调用的代码:
$(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 代码:
<?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 请求的脚本。
-
@chumkiu 令人惊讶的是,这是我的实际代码!简单而且非常,但是非常慢!
-
如果我在没有 Ajax 的情况下直接在浏览器中输入脚本,它的加载速度非常快。
标签: javascript php ajax jquery