简体   繁体   中英

Access-Control-Allow-Origin not present for localhost

I'm using the Instagram api and have successfully retrieved an access_token, along with using HTML5 geolocation to retrieve a user's location. This data is then used to construct the string to access the instagram endpoint:

https://api.instagram.com/v1/media/search" + coordsquery + "&access_token=" + access

I have set my redirect uri from Instagram as http://localhost/explorer and my request for access_token in my application is var redirect = "http://localhost/explorer";

However I still get the error. I read that Chrome has a bug or something with localhost and making calls like this so I tried in firefox. Same deal.

I also read somewhere about appending ?callback=? to the GET request url. Also no dice.

I still don't know what was wrong with my original:

$.get(querystring, function( data ) {
            console.log(data);
        });

but I ended up trying this:

$.ajax({
            type: "GET",
            dataType: "jsonp",
            url: querystring, 
            success: function(data) {
                console.log(data);
            }
        });

and it worked just fine.

If someone could possibly explain why the second approach worked where the first failed I'd be forever grateful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM