gpt4 book ai didi

php - 使用 jquery ajax 仅从 mysql 获取新行

转载 作者:行者123 更新时间:2023-12-01 07:35:07 25 4
gpt4 key购买 nike

Possible Duplicate:
jquery/ajax load new content when available

我有一个名为 news 的表,其中包含 3 个字段,即(id、新闻、时间),并且每 3 分钟后我有一个 setInterval 从 google 或任何新闻网站获取新闻 ....

现在我只想获取每 5 分钟后插入的新行...使用 jquery $.ajax()...我该怎么做...

我要重新加载整个表还是有办法只获取新的表...

最佳答案

有一个变量来存储返回行的最新 ID 号,然后将其包含在 AJAX 调用中(让 PHP 服务器端脚本仅返回 ID 大于该值的行)。

在调用页面

var latestID = 0;
...
/* Within the Variables Section for the AJAX Call */
laterThan : latestID
...
/* Within the Success AJAX Function */
latestID = data.highestID; /* Where "data.highestID" is the highest ID returned */

在通过 AJAX 调用的服务器端脚本中

<?php
...
/* Within the SQL Query creating the returned rows */
'WHERE
...
AND `id` > '.( isset( $_GET['latestID'] ) ? (int) $_GET['latestID'] : 0 )

关于php - 使用 jquery ajax 仅从 mysql 获取新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2959190/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com