加载包含Javascript的外部PHP文件
我正在努力使以下各项发挥作用。我的页脚文件中有以下代码: footer.php:加载包含Javascript的外部PHP文件,javascript,jquery,ajax,Javascript,Jquery,Ajax,我正在努力使以下各项发挥作用。我的页脚文件中有以下代码: footer.php: <script type="text/javascript"> $(document).ready(function(){ $.ajax({ url: '', type: 'GET', dataType: "script", success: function(data){ //data is returned back $('#latestforumposts').html(data
<script type="text/javascript">
$(document).ready(function(){
$.ajax({
url: '',
type: 'GET',
dataType: "script",
success: function(data){
//data is returned back
$('#latestforumposts').html(data);
}
});
});
</script>
现在,它将加载脚本,而不是显示加载到div#latestforumposts中的html,而是用它刷新整个页面内容。知道它为什么不加载到div吗?jQuery
$(document).ready(function()
{
update(false);
});
function update(load)
{
if(load)
{
$.get(url,function(data)
{
$('#latestforumposts').html(data);
});
}
setTimeout(function(){update(true)},5000);
}
PHP(/forumposts.PHP)
对于(x=0;x<5;x++)
{
$('#new#posts tbody').append(''+threads[x].poster+'');
}
HTML
<div id="latestforumposts"></div>
使用html
作为数据类型
,它总是给我一个错误,没有定义线程。正在从该external.php文件中提取。好的,所以我添加了一行:用更新的页面编辑了我的原始问题。我看起来像是在刷新整个页面,因为document.writeln()
。但问题是,VBulletin已经内置了一项功能,以避免必须遍历数据库。哦,对不起,我不知道这一点。也许我可以想点别的。
$(document).ready(function()
{
update(false);
});
function update(load)
{
if(load)
{
$.get(url,function(data)
{
$('#latestforumposts').html(data);
});
}
setTimeout(function(){update(true)},5000);
}
<script type="text/javascript" src="http://www.habboxforum.com/external.php?forumids=1382,1384,4,5,14,1410,7,85,40,43,124,123,24,30,306,34,446,38,214,1409,249,767,69,71,73,134,56,45,1230,54,135,1424,1425,601,893,209,1086&type=js"></script>
<script type="text/javascript">
for(x = 0; x < 5; x++)
{
$('#new_posts tbody').append('<tr class="forumnewposts"><td><div class="forumpostwidth"><a target="_blank" href="http://www.habboxforum.com/showthread.php?t='+threads[x].threadid+'">'+threads[x].title+'</a></div></td><td><div class="forumuserwidth">'+threads[x].poster+'</div></td></tr>');
}
</script>
<table id="new_posts"><tbody></tbody></table>
<div id="latestforumposts"></div>