instagram jquery ajax type="GET, can't get around CORS

无人久伴 提交于 2019-11-26 22:02:11

问题


I have received this error

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

I am trying to make a $.ajax call to the instragram api. I am using the https://api.instagram.com/v1/tags/nofilter/media/recent?client_id=CLIENT-ID

end point. I have put in my client-ID and I get the CORS error. It can't find my localhost:3000, I don't know what to do. the endpoint works in postman when I tested. So I know it has something to do with CORS but I don't know who to set other options.

function getLooks(){

$.ajax({
  url: "https://api.instagram.com/v1/tags/ootd/media/recent?client_id=someidnumbersxxxxxxxxxxxxxx",
  type: "GET",
  crossDomain: true,
  success: function(data){
    console.log(data);
    _.each(data, function(look){
      console.log(look);

      //var $look = template(look);
      //$("#looks-container").append($look);
    });
  }
});

}

Any have this issues. Any help or link to other material will help.


回答1:


You can use the dataType jsonp for GET requests.

$.ajax({
    url: "https://api.instagram.com/v1/tags/ootd/media/recent?client_id=someidnumbersxxxxxxxxxxxxxx",
    type: "GET",
    crossDomain: true,
    dataType: "jsonp",
    success: function(data){
        console.log(data);
        _.each(data, function(look){
            console.log(look);

            //var $look = template(look);
            //$("#looks-container").append($look);
        });
    }
});


来源:https://stackoverflow.com/questions/31505596/instagram-jquery-ajax-type-get-cant-get-around-cors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!