【问题标题】:Reloading a page inside of a <div> with $_GET使用 $_GET 重新加载 <div> 内的页面
【发布时间】:2023-03-23 02:45:02
【问题描述】:

以下页面加载到我的 index.php 中。我最初使用以下链接调用它:Import Mutuals

这部分很有效。我遇到的问题是底部的刷新代码: var auto_refresh = setInterval(function(){\$('#import').show('fast').load('fb_import_statuses.php?i=$ i').show('fast');}, 1000);

我希望它最初使用记录 1 加载,然后继续刷新,更新我的 SQL 直到它达到记录 255。如果我在 DIV 之外使用 Meta Refresh 执行相同的代码,它会逐步执行序列,但使用此 JavaScript刷新它的顺序如下:

1、2、3、2、3、4、2、3、4、5等...

我怎样才能让它排序为 1、2、3、4、5、6、7 等...

require 'batch_include.php';
require 'html_head.php';

if (isset($_GET['i'])){$i = $_GET["i"];} else {$i=0;}

$getcount = mysql_query("SELECT COUNT(id) AS get_count FROM people", $conn);
while ($row = mysql_fetch_array($getcount)){$get_count = "".$row{'get_count'}."";}

   $result = mysql_query("SELECT id FROM people LIMIT ".$i.",1", $conn);
   while ($row = mysql_fetch_array($result)){                                    
        $get_uid = addslashes("".$row{'id'}.""); 

    $me_friends = $facebook->api(array('method' => 'fql.query', 'query' => 'SELECT     status_id, message, source, time FROM status WHERE uid="'.$get_uid.'" LIMIT 5'));
    foreach ($me_friends as $fkey=>$me_friends){
        $get_status_id = $me_friends['status_id']; 
        $get_message = addslashes($me_friends['message']); 
        $get_source = $me_friends['source']; 
        $get_timestamp = $me_friends['time']; 

    $insert = mysql_query("INSERT INTO statuses (id, message, source, timestamp, uid)      VALUES ('$get_status_id', '$get_message', '$get_source', '$get_timestamp', '$get_uid')",     $conn);        
    }  
}             
$i = $i + 1;

if ($i<=$get_count){
echo "$i";
echo "<script>var auto_refresh = setInterval(function(){\$('#import').show('fast').load('fb_import_statuses.php?i=$i').show('fast');}, 1000);    </script>";
}

else {    
    echo "Import complete:  ";
    echo "<img src='/images/check.png'>";

    } 

【问题讨论】:

  • 好吧,我的一些问题没有解决,因为我使用了代码。但是代码在我的 index.php 中的 DIV 内被调用

标签: javascript ajax html refresh


【解决方案1】:

问题是你添加了多个setInterval 函数(每次加载页面时你echo 另一个方法)。尝试将您的刷新方法放在div 之外,或者让它调用一个包含php 代码的函数,该代码负责从数据库中检索信息。

如果您不必每秒刷新页面,您可以使用一个 php 文件从 db 获取所有数据并以某种形式返回(例如 json)。我认为这是最好的方法。

【讨论】:

  • 感谢 maialithar。我正在使用 FQL 从 FB 导入我所有的朋友,当我一次导入多个朋友时,FQL 超时。所以我必须这样做一次导入一个,同时一个接一个地循环我所有的朋友。
  • 这将是一种“蛮力”,并不是最好的解决方案,但您可以将间隔时间设置为较高的值,以确保该函数只执行一次。
  • 看起来我是通过添加 clearInterval(auto_refresh);在 var auto_refresh 之前。感谢您为我指明正确的方向:)
猜你喜欢
  • 1970-01-01
  • 2022-12-14
  • 1970-01-01
  • 1970-01-01
  • 2014-09-06
  • 2013-09-18
  • 2016-04-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多