1

我的 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>';
?>
4

2 回答 2

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'));
于 2013-08-01T08:46:44.973 回答
0

尝试这个

<script type="text/javascript">
var auto_refresh_stats = setInterval(
function (){
  $('.userStats').load('get_user_stats.php');
}, 1000 );
</script>
于 2013-08-01T08:50:13.263 回答