0

I'm just trying to run a basic jQuery ajax get request on instagram's api.

$.ajax({
    url:"https://www.instagram.com/page?__a=1",
    success:function(data){
         console.log(data)
    }
});

I'm getting this message:

Access to XMLHttpRequest at 'https://www.instagram.com/page?__a=1' from origin 'https://example.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

I've tried adding countless different Wordpress CORS solutions from Stack Overflow to my functions.php file, and none of stop this issue from persisting. I don't know why these solutions are not working, and I frankly don't know how to debug what's going wrong with this.

Most solutions involve stating this:

add_action( 'rest_api_init', function(){
    header( "Access-Control-Allow-Origin: *" );
});

I'm running Wordpress 5.6.2 The javascript above did work without any CORS restrictions in the past. Didn't notice when exactly it stopped working.

Any ideas?

Thanks!

1
  • Anyone got any ideas? – Fluxian Mar 9 at 16:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.