我正在尝试以下操作。我有这样的代码在我的页脚文件:加载包含Javascript的外部PHP文件
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>
这是文件forumposts.php:
<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++)
{
document.writeln("<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>
基本上,文件似乎并没有加载在div #latestforumposts
像它的意思,但如果你直接访问forumposts.php页面,它显示了它应该的内容(例如在forumposts.php中的脚本)。
如何拖动该脚本并将其放入我的页面上的div。我需要这样做的原因是我需要它每x秒钟自动刷新一次。
UPDATE:
好了,所以我现在在我的页脚下面的代码:
<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">
$(document).ready(function(){
$.ajax({
url: '',
type: 'GET',
dataType: "html",
success: function(data){
//data is returned back
$('div#latestforumposts').html(data);
}
});
});
</script>
这就是现在加载脚本,但不是显示在到div加载HTML #latestforumposts它只是刷新整个页面的内容。任何想法为什么它不加载到div?
使用'html'为'dataType' – 2012-08-14 09:42:38
这只是不断给我的线程没有定义的错误。这是从该external.php文件中提取的。 好的,所以我加了一行: 就在ajax脚本之前,所以线程被定义了,但现在网站刷新到该php内容,而不是将其加载到正确的div中。 – Tenatious 2012-08-14 09:46:52
用更新后的页面编辑我的原始问题。 – Tenatious 2012-08-14 09:53:38