[英]Loading an external PHP file that contains Javascript
I am trying to get the following to work. 我正在努力使以下工作。 I have this code in my footer file: 我的页脚文件中有以下代码:
footer.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>
And this is the file forumposts.php: 这是文件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>
Basically, the file doesn't seem to load in to the div #latestforumposts
like it is meant to yet if you visit the forumposts.php page directly it shows the content like it is supposed to (eg the script in forumposts.php works). 基本上,该文件似乎并没有像它#latestforumposts
那样加载到div #latestforumposts
,但是如果您直接访问forumposts.php页面,它会显示应有的内容(例如,forumposts.php中的脚本有效) 。
How can I drag that script and place it in a div on my page. 如何拖动该脚本并将其放在页面上的div中。 The reason I need to do this is I need it to auto-refresh every x number of seconds. 我需要执行此操作的原因是,我需要它每隔x秒自动刷新一次。
UPDATE: 更新:
Okay, so I now have the following code in my footer: 好的,现在我的页脚中有以下代码:
<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>
This now loads the script but instead of displaying the html that is loaded in to the div#latestforumposts it just refreshes the whole page content with it. 现在,这将加载脚本,但与其显示加载到div#latestforumposts中的html,它只是刷新整个页面内容。 Any idea why it doesn't load in to the div? 知道为什么它不加载到div吗?
jQuery 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) 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 的HTML
<div id="latestforumposts"></div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.