dongliqin6939 2016-10-14 09:49
浏览 44

php ajax分页从另一个域获取数据

So, i have a site that grabs data from another one of my sites and displays it accordingly. Things are starting to slow down as there is now a lot of data and the query i have grabs all results. So its time to implement some pagination.

Here is my jQuery to grab the data:

jQuery(document).ready(function(){
    jQuery(document).on('click','.show_more',function(){
        var ID = jQuery(this).attr('id');
        jQuery('.show_more').hide();
        jQuery('.loding').show();
        jQuery.ajax({
            type:'POST',
            async: true,
                        crossDomain : true,
            url:'http://example.com/retailers/products.php?apikey=123456&retailer=Test',
            data:'id='+ID,
            success:function(html){
                jQuery('#show_more_main'+ID).remove();
                jQuery('.retailitems').append(html);
            }
        }); 
    });
});

With the above i get the following error:

 No 'Access-Control-Allow-Origin' header is present on the requested resource.

I know i can use datatype: jsonp but is there an alternative i can use, as i own the other domain? Is there something i can setup on the other domain to allow this?

  • 写回答

2条回答 默认 最新

  • dragon456101 2016-10-14 10:02
    关注

    Add .htaccess file at the root folder to remove the cross origin issue on the domain from where you are getting data..

    <IfModule mod_rewrite.c>
    RewriteEngine On
    </IfModule>
    Header always set Access-Control-Allow-Origin "*"
    Header always set Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Access-Control-Allow-Origin"
    Header always set Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
    
    评论

报告相同问题?

悬赏问题

  • ¥50 comsol稳态求解器 找不到解,奇异矩阵有1个空方程返回的解不收敛。没有返回所有参数步长;pid控制
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功