我想在我的网站上实现无限滚动,我正在加载用户的数据,为此我使用了这个Ajax脚本。
$(document).ready(function(){
var limit = 10;
var start = 0;
var action = 'inactive';
function load_country_data(limit, start)
{
$.ajax({
url:"pagination.php",
method:"POST",
data:{limit:limit, start:start},
cache:false,
success:function(data)
{
$('#load_data').append(data);
if(data == '')
{
$('#load_data_message').html("<button type='button' class='btn btn-info'>No Data Found</button>");
action = 'active';
}
else
{
$('#load_data_message').html("<button type='button' class='btn btn-info'>Loading data</button>");
action = "inactive";
}
}
});
}
if(action == 'inactive')
{
action = 'active';
load_country_data(limit, start);
}
$(window).scroll(function(){
if($(window).scrollTop() + $(window).height() > $("#load_data").height() && action == 'inactive')
{
action = 'active';
start = start + limit;
setTimeout(function(){
load_country_data(limit, start);
}, 1000);
}
});
});
所以现在当我运行该页面时,它在控制台日志中显示了这个错误。
Access to XMLHttpRequest at 'https://example.com/pagination.php' from origin 'http://example.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
但这个东西在Postman中完美地工作,并给我输出.请帮助我。谢谢你的帮助