gpt4 book ai didi

javascript - AJAX请求成功但返回空数据

转载 作者:行者123 更新时间:2023-12-03 11:43:05 25 4
gpt4 key购买 nike

我的 MySQL 中有一个表,我使用 FOR EACH 循环在页面上显示数据。之后,当数据库中插入新的原始数据时,我会在每次 FOR EACH 循环时执行 ajax 请求进行更新。

AJAX请求成功,但返回空数据。我不明白我做错了什么。我将不胜感激任何帮助。也许我做错了什么,WordPress 让我的代码变得奇怪?

我使用 FOR EACH 循环显示数据的文件:ajax.php

// DB Connection (Wordpress)

global $wpdb;

$_IL_START = 0;
$_IL_LIMIT = 10;

if( isset($_GET['paged']) ){
$_IL_ID = $_GET['paged'];
$_IL_START = ($_IL_ID-1) * $_IL_LIMIT;
}

$_IL_QUERY_INTERNAL = $wpdb->get_results( "SELECT * FROM $_IL_TABLE_NAME_INTERNAL ORDER BY il_id DESC LIMIT $_IL_START, $_IL_LIMIT");

//FOR EACH Loop

echo '<ul id="list">';
foreach($_IL_QUERY_INTERNAL as $_IL_RESULT_DATA)
{
echo $_IL_RESULT_DATA->il_name;
echo $_IL_RESULT_DATA->il_email;
$_IL_RESULT_DATA->il_date;
}
echo '</ul>';

我用 jquery 调用 ajax.php 的文件:(display.php)

//require once the FOR EACH Loop

require_once ($_SERVER["DOCUMENT_ROOT"]."/ajax.php");

//and the JS Code

<script type="text/javascript" >
fetch();
function fetch(){
jQuery.ajax({
cache: false,
url: '/ajax.php',
success: function(data) {
jQuery(data).hide().prependTo("#list").slideDown("slow");
if(jQuery("#list li").length > 15){
jQuery('#list li:gt(14)').remove();
}
console.log(data);
setTimeout("fetch()", 100);
}
});
}
</script>

当我制作 console.log(data) 时,仅打印此 < ul id="list" >< /ul >没有别的。

var_dump($_IL_QUERY_INTERNAL) 的结果;

array(3) { [0]=> object(stdClass)#427 (11) { ["il_id"]=> string(1) "6" ["il_name"]=> string(11) "Ion Luchian" ["il_email"]=> string(14) "adasdds@ffl.ll" ["il_from_mt4"]=> string(10) "2088408090" ["il_from_mt4_currency"]=> string(3) "USD" ["il_to_mt4"]=> string(6) "534534" ["il_to_mt4_currency"]=> string(3) "USD" ["il_comments"]=> string(0) "" ["il_status"]=> string(8) "approved" ["il_user_ip"]=> string(9) "127.0.0.1" ["il_date"]=> string(10) "2014-09-18" } [1]=> object(stdClass)#426 (11) { ["il_id"]=> string(1) "4" ["il_name"]=> string(11) "Ion Luchian" ["il_email"]=> string(13) "dasdas@.gg.gg" ["il_from_mt4"]=> string(10) "2088408090" ["il_from_mt4_currency"]=> string(3) "USD" ["il_to_mt4"]=> string(7) "3112312" ["il_to_mt4_currency"]=> string(3) "USD" ["il_comments"]=> string(51) "this my comment, appears only if the comment exists" ["il_status"]=> string(8) "approved" ["il_user_ip"]=> string(9) "127.0.0.1" ["il_date"]=> string(10) "2014-09-18" } [2]=> object(stdClass)#430 (11) { ["il_id"]=> string(1) "3" ["il_name"]=> string(11) "Ion Luchian" ["il_email"]=> string(14) "terterte@tt.ll" ["il_from_mt4"]=> string(10) "2088408090" ["il_from_mt4_currency"]=> string(3) "USD" ["il_to_mt4"]=> string(6) "345345" ["il_to_mt4_currency"]=> string(3) "USD" ["il_comments"]=> string(0) "" ["il_status"]=> string(8) "approved" ["il_user_ip"]=> string(9) "127.0.0.1" ["il_date"]=> string(10) "2014-09-18" } }

这是我的分页:

$_IL_ROWS_COUNT = mysql_num_rows(mysql_query("select * from $_IL_TABLE_NAME_INTERNAL"));
$_IL_TOTAL = ceil( $_IL_ROWS_COUNT / $_IL_LIMIT );

if($_IL_LIMIT < $_IL_ROWS_COUNT){
echo '<span class="il_pagination_block_admin">';
if( $_IL_ID > 1 )
{
echo "<a href='?page=il_internal_transfer&tab=il_internal_transfer&paged=".($_IL_ID-1)."' class='il_pagination_prev'><span class='il_pagination_prev_icon'></span></a>";
}

echo "<ul class='il_pagination'>";
for( $i = 1; $i <= $_IL_TOTAL; $i++ )
{
if( $i == $_IL_ID ) { echo "<li class='il_pagination_current'>".$i."</li>"; }

else { echo "<li><a href='?page=il_internal_transfer&tab=il_internal_transfer&paged=".$i."'>".$i."</a></li>"; }
}
echo "</ul>";
if( $_IL_ID != $_IL_TOTAL )
{
echo "<a href='?page=il_internal_transfer&tab=il_internal_transfer&paged=".( $_IL_ID + 1 )."' class='il_pagination_next'><span class='il_pagination_next_icon'></span></a>";
}

echo "</span>";

最佳答案

说明

on the server page (php) that receive the facebook notice, you have to put an extra check so

if( facebook_data_come ) {

// 1 - insert the new data inside your table

// 2 - on a separate database table that you will call for example facebook_notification_check where you have an INT of 0 or 1 (default to 0), update it to 1 after the first step above.

// 3 - on the ajax php page you will first check if facebook_notification_check is equal to 1, if so you will continue with your code and reset the facebook_notification_check back to 0 otherwise you return an empty string...

}
<小时/>
<?php
global $wpdb;
$html = 'unknown error';
$query = "SELECT * FROM $_IL_TABLE_NAME_INTERNAL ORDER BY il_id DESC LIMIT $_IL_START, $_IL_LIMIT";
if($_IL_QUERY_INTERNAL = $wpdb->get_results($query)){
if(count($_IL_QUERY_INTERNAL)){
foreach($_IL_QUERY_INTERNAL as $_IL_RESULT_DATA)
{
$html = '<li>'. $_IL_RESULT_DATA->il_name . $_IL_RESULT_DATA->il_email . $_IL_RESULT_DATA->il_date .'</li>';
}
} else {
$html = '';
}
} else {
header("HTTP/1.0 500 Internal server error");
$html = mysql_error() . " | sql query : " . $query;
}
echo $html;
?>
<小时/>
<ul id="list"></ul>

<script type="text/javascript" >
fetch();
function fetch(){
jQuery.ajax({
cache: false,
url: '/ajax.php',
success: function(data) {
console.log(data);
if(data!=''){

jQuery(data).prependTo("#list");
jQuery('#list li:first-child').slideDown("slow");

setTimeout("fetch()", 100);
}
},
error: function(jqXHR, textStatus, errorThrown){
console.log(jqXHR);
}
});
}
</script>

关于javascript - AJAX请求成功但返回空数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26175299/

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