How to retrieve JSONP using fetch?












-1















I'm not able to load the data from this public endpoint:



http://api.flickr.com/services/feeds/photos_public.gne?format=json



I get the following error:



Access to fetch at 'http://api.flickr.com/services/feeds/photos_public.gne?format=json' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.


How to do this?










share|improve this question























  • A public API is not necessarily available from web client JavaScript. If Flickr is not setting CORS headers, then the only option is your own server-side proxy to fetch it for your client.

    – Pointy
    Jan 2 at 19:08











  • stackoverflow.com/questions/33423853/…

    – Diodeus - James MacFarlane
    Jan 2 at 19:09






  • 2





    I don't think you would even want to use fetch() with this. You would still follow the old pattern of creating a named, global function that the JSONP script will call and then create a script that points to the JSONP returning endpoint.

    – zero298
    Jan 2 at 19:10











  • Possible duplicate of Axios and Fetch both result in CORS error but Postman doesn't

    – Amy
    Jan 2 at 19:39
















-1















I'm not able to load the data from this public endpoint:



http://api.flickr.com/services/feeds/photos_public.gne?format=json



I get the following error:



Access to fetch at 'http://api.flickr.com/services/feeds/photos_public.gne?format=json' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.


How to do this?










share|improve this question























  • A public API is not necessarily available from web client JavaScript. If Flickr is not setting CORS headers, then the only option is your own server-side proxy to fetch it for your client.

    – Pointy
    Jan 2 at 19:08











  • stackoverflow.com/questions/33423853/…

    – Diodeus - James MacFarlane
    Jan 2 at 19:09






  • 2





    I don't think you would even want to use fetch() with this. You would still follow the old pattern of creating a named, global function that the JSONP script will call and then create a script that points to the JSONP returning endpoint.

    – zero298
    Jan 2 at 19:10











  • Possible duplicate of Axios and Fetch both result in CORS error but Postman doesn't

    – Amy
    Jan 2 at 19:39














-1












-1








-1








I'm not able to load the data from this public endpoint:



http://api.flickr.com/services/feeds/photos_public.gne?format=json



I get the following error:



Access to fetch at 'http://api.flickr.com/services/feeds/photos_public.gne?format=json' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.


How to do this?










share|improve this question














I'm not able to load the data from this public endpoint:



http://api.flickr.com/services/feeds/photos_public.gne?format=json



I get the following error:



Access to fetch at 'http://api.flickr.com/services/feeds/photos_public.gne?format=json' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.


How to do this?







javascript ajax cors fetch






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 2 at 19:05









TK123TK123

10.8k36118161




10.8k36118161













  • A public API is not necessarily available from web client JavaScript. If Flickr is not setting CORS headers, then the only option is your own server-side proxy to fetch it for your client.

    – Pointy
    Jan 2 at 19:08











  • stackoverflow.com/questions/33423853/…

    – Diodeus - James MacFarlane
    Jan 2 at 19:09






  • 2





    I don't think you would even want to use fetch() with this. You would still follow the old pattern of creating a named, global function that the JSONP script will call and then create a script that points to the JSONP returning endpoint.

    – zero298
    Jan 2 at 19:10











  • Possible duplicate of Axios and Fetch both result in CORS error but Postman doesn't

    – Amy
    Jan 2 at 19:39



















  • A public API is not necessarily available from web client JavaScript. If Flickr is not setting CORS headers, then the only option is your own server-side proxy to fetch it for your client.

    – Pointy
    Jan 2 at 19:08











  • stackoverflow.com/questions/33423853/…

    – Diodeus - James MacFarlane
    Jan 2 at 19:09






  • 2





    I don't think you would even want to use fetch() with this. You would still follow the old pattern of creating a named, global function that the JSONP script will call and then create a script that points to the JSONP returning endpoint.

    – zero298
    Jan 2 at 19:10











  • Possible duplicate of Axios and Fetch both result in CORS error but Postman doesn't

    – Amy
    Jan 2 at 19:39

















A public API is not necessarily available from web client JavaScript. If Flickr is not setting CORS headers, then the only option is your own server-side proxy to fetch it for your client.

– Pointy
Jan 2 at 19:08





A public API is not necessarily available from web client JavaScript. If Flickr is not setting CORS headers, then the only option is your own server-side proxy to fetch it for your client.

– Pointy
Jan 2 at 19:08













stackoverflow.com/questions/33423853/…

– Diodeus - James MacFarlane
Jan 2 at 19:09





stackoverflow.com/questions/33423853/…

– Diodeus - James MacFarlane
Jan 2 at 19:09




2




2





I don't think you would even want to use fetch() with this. You would still follow the old pattern of creating a named, global function that the JSONP script will call and then create a script that points to the JSONP returning endpoint.

– zero298
Jan 2 at 19:10





I don't think you would even want to use fetch() with this. You would still follow the old pattern of creating a named, global function that the JSONP script will call and then create a script that points to the JSONP returning endpoint.

– zero298
Jan 2 at 19:10













Possible duplicate of Axios and Fetch both result in CORS error but Postman doesn't

– Amy
Jan 2 at 19:39





Possible duplicate of Axios and Fetch both result in CORS error but Postman doesn't

– Amy
Jan 2 at 19:39












1 Answer
1






active

oldest

votes


















1














Jsonp doesn't work like this as its designed to work around the same origin policy. If the flickr API supports CORS, you can use that with fetch, but if you want to use jsonp, you need to add a script tag and a callback. Further reading: https://en.wikipedia.org/wiki/JSONP



Example:



<script type="application/javascript">
window.jsonFlickrFeed = function(response) {
alert(response);
};
</script>
<script type="application/javascript" src="http://api.flickr.com/services/feeds/photos_public.gne?format=json">
</script>





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54011837%2fhow-to-retrieve-jsonp-using-fetch%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Jsonp doesn't work like this as its designed to work around the same origin policy. If the flickr API supports CORS, you can use that with fetch, but if you want to use jsonp, you need to add a script tag and a callback. Further reading: https://en.wikipedia.org/wiki/JSONP



    Example:



    <script type="application/javascript">
    window.jsonFlickrFeed = function(response) {
    alert(response);
    };
    </script>
    <script type="application/javascript" src="http://api.flickr.com/services/feeds/photos_public.gne?format=json">
    </script>





    share|improve this answer




























      1














      Jsonp doesn't work like this as its designed to work around the same origin policy. If the flickr API supports CORS, you can use that with fetch, but if you want to use jsonp, you need to add a script tag and a callback. Further reading: https://en.wikipedia.org/wiki/JSONP



      Example:



      <script type="application/javascript">
      window.jsonFlickrFeed = function(response) {
      alert(response);
      };
      </script>
      <script type="application/javascript" src="http://api.flickr.com/services/feeds/photos_public.gne?format=json">
      </script>





      share|improve this answer


























        1












        1








        1







        Jsonp doesn't work like this as its designed to work around the same origin policy. If the flickr API supports CORS, you can use that with fetch, but if you want to use jsonp, you need to add a script tag and a callback. Further reading: https://en.wikipedia.org/wiki/JSONP



        Example:



        <script type="application/javascript">
        window.jsonFlickrFeed = function(response) {
        alert(response);
        };
        </script>
        <script type="application/javascript" src="http://api.flickr.com/services/feeds/photos_public.gne?format=json">
        </script>





        share|improve this answer













        Jsonp doesn't work like this as its designed to work around the same origin policy. If the flickr API supports CORS, you can use that with fetch, but if you want to use jsonp, you need to add a script tag and a callback. Further reading: https://en.wikipedia.org/wiki/JSONP



        Example:



        <script type="application/javascript">
        window.jsonFlickrFeed = function(response) {
        alert(response);
        };
        </script>
        <script type="application/javascript" src="http://api.flickr.com/services/feeds/photos_public.gne?format=json">
        </script>






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 2 at 19:18









        Stephen CrosbyStephen Crosby

        729417




        729417
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54011837%2fhow-to-retrieve-jsonp-using-fetch%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas