【发布时间】:2014-12-09 20:37:17
【问题描述】:
有一个simple ajax 用于将内容加载到页面中。 我想要的是加载的内容在页面上显示之前等待一段时间。 (在淡入之前) 在 #body 淡入之后,我尝试使用 jQuery 的 .delay() 函数,但它不起作用。 谁能指出我正确的方向?
提前感谢您的宝贵时间
JS
var default_content="";
$(document).ready(function(){
checkURL();
$('ul li a').click(function (e){
checkURL(this.hash);
});
//filling in the default content
default_content = $('#pageContent').html();
setInterval("checkURL()",250);
});
var lasturl="";
function checkURL(hash)
{
if(!hash) hash=window.location.hash;
if(hash != lasturl)
{
lasturl=hash;
// FIX - if we've used the history buttons to return to the homepage,
// fill the pageContent with the default_content
if(hash=="")
$('#pageContent').html(default_content);
else
loadPage(hash);
}
}
function loadPage(url)
{
url=url.replace('#page','');
$('#body').hide ();
$('#loading').css('visibility','visible');
$.ajax({
type: "POST",
url: "load_page.php",
data: 'page='+url,
dataType: "html",
success: function(msg){
if(parseInt(msg)!=0)
{
$('#pageContent').html(msg);
$('#body').fadeIn( 'slow' );
$('#loading').css('visibility','hidden');
}
}
});
}
PHP
if(!$_POST['page']) die("0");
$page = (int)$_POST['page'];
if(file_exists('pages/page_'.$page.'.html'))
echo file_get_contents('pages/page_'.$page.'.html');
else echo 'There is no such page!';
?>
【问题讨论】:
标签: javascript php jquery html ajax