我的javascript代码无效。我去了页面,它正在显示内容。为什么不将数据附加到.userStats? invest_process.php包含获取PHP中显示的值的信息。这不是造成这个问题的原因。谢谢,下面的代码。
HTML代码:
<div id="content1" class="tabscontent">
<p>
<span class="userStats"></span>
</p>
</div>
JavaScript的:
<script type="text/javascript">
var auto_refresh_stats = setInterval(
function (){
$('.userStats').load('get_user_stats.php').show();
}, 1000 );
</script>
PHP代码:
<?php
require 'invest_process.php';
echo
'<span><h3>You have:
' . $select_invested['amtInvested'] .
' Invested in GigaDice | You have:
' . $select_invested['amtInvested']/$select_invested_total['siteInvested']*100 .
' % of the site\'s bankroll</span></h3> <span><h3> You have
' . $select_balance_gg['gigagold'] .
' in GG Balance | You have profitted:
' . $siteProfit*$select_invested['amtInvested']/$select_invested_total['siteInvested'] .
'</span></h3>';
?>
答案 0 :(得分:1)
添加$(document).ready()
块
$(document).ready(function()
{
var auto_refresh_stats = setInterval(
function ()
{
$('.userStats').load('get_user_stats.php').show(); // if you want to replace
}, 1000 );
});
如果要附加内容,请使用以下
$('.userStats').append($('<div>').load('get_user_stats.php'));
答案 1 :(得分:0)
试试这个
<script type="text/javascript">
var auto_refresh_stats = setInterval(
function (){
$('.userStats').load('get_user_stats.php');
}, 1000 );
</script>