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"
    
    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)