我正在嘗試以下操作。我有這樣的代碼在我的頁腳文件:加載包含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