[英]Loading an external PHP file that contains Javascript
我正在努力使以下工作。 我的頁腳文件中有以下代碼:
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>
這是文件forumpostposts.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>
基本上,該文件似乎並沒有像它#latestforumposts
那樣加載到div #latestforumposts
,但是如果您直接訪問forumposts.php頁面,它會顯示應有的內容(例如,forumposts.php中的腳本有效) 。
如何拖動該腳本並將其放在頁面上的div中。 我需要執行此操作的原因是,我需要它每隔x秒自動刷新一次。
更新:
好的,現在我的頁腳中有以下代碼:
<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#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)
<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>
的HTML
<div id="latestforumposts"></div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.