如果在PHP中使用Ajax进行滚动,会显示出这样的访问XMLHttpRequest在

问题描述 投票:0回答:1

我想在我的网站上实现无限滚动,我正在加载用户的数据,为此我使用了这个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中完美地工作,并给我输出.请帮助我。谢谢你的帮助

php ajax infinite-scroll
1个回答
0
投票

我不知道为什么它能在Postman中工作,但这是一个很好的例子。CORS 问题,具体 这个.

看起来你也在尝试访问你的。pagination.php 当运行您所包含的JS代码的页面没有使用 SSL我相信除了你收到的错误中所引用的之外,这也是一种CORS违规。

© www.soinside.com 2019 - 2024. All rights reserved.