我希望在向下滚动窗口时加载照片,但我在ajax请求中遇到错误,我想知道我看不到的错误是什么?
我得到的错误如下
POST http://localhost/test/wp-admin/admin-ajax.php 400 (Bad Request)
遵循我的代码:
jQuery
jQuery(document).ready(function () {
let limit = 4;
let start = 0;
let action = \'inactive\';
function load_country_data(limit, start) {
jQuery.ajax({
url: "http://localhost/test/wp-admin/admin-ajax.php",
method: "POST",
data: {limit: limit, start: start, action: \'test\'},
cache: false,
success: function (data) {
jQuery(\'#load_data\').append(data);
if (data === \'\') {
jQuery(\'#load_data_message\').html("<button type=\'button\'> No Data Found </button>");
action = \'active\';
} else {
jQuery(\'#load_data_message\').html("<button type=\'button\'> Please Wait... </button>")
action = "inactive";
}
}
});
}
if (action === \'inactive\') {
action = \'active\';
load_country_data(limit, start);
}
jQuery(window).scroll(function () {
if (jQuery(window).scrollTop() + jQuery(window).height() > jQuery(\'#load_data\').height() &&
action == \'inactive\') {
action = \'active\';
start = start + limit;
setTimeout(function () {
load_country_data(limit, start);
}, 1000);
}
});
});
functions.php
add_action(\'wp_ajax_test\', \'test\');
add_action(\'wp_ajax_nopriv_test\', \'test\');
function test(){
global $wpdb;
if(isset($_POST["limit"], $_POST["start"])){
$d = $_POST[\'start\']. ",".$_POST[\'limit\'];
$list = $wpdb->get_results("Select * From {$wpdb->prefix}load_more ORDER BY id ASC LIMIT ".$d);
foreach ($list as $val2) {
echo \'
<h3>\'.$val2->header.\'</h3>
\';
}
}
}
提前感谢您的帮助
实际上,数据值应该为空,但它从不进入if条件,始终返回0