How to retrieve JSONP using fetch?
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
add a comment |
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
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 usefetch()
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
add a comment |
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
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
javascript ajax cors fetch
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 usefetch()
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
add a comment |
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 usefetch()
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
add a comment |
1 Answer
1
active
oldest
votes
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>
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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>
add a comment |
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>
add a comment |
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>
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>
answered Jan 2 at 19:18
Stephen CrosbyStephen Crosby
729417
729417
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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