-
Notifications
You must be signed in to change notification settings - Fork 22.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fetch Basic Sample Code 404 #31841
Comments
Thanks for flagging, alternatively, we could do: // Define the function
async function logContributors() {
const r = await fetch("https://developer.mozilla.org/en-US/docs/Glossary/TOFU/contributors.txt");
const textData = await r.text();
console.log(textData);
}
// Call the function
logContributors(); If we don't want to point too much traffic at |
This is an interesting suggestion. But even if we use https://jsonplaceholder.typicode.com/, you won't be able to send requests from developer.mozilla.org, because of d.m.o.'s CSP settings. So if a reader opens the console while reading the page and pastes examples in, it won't work. Perhaps it is even more confusing in that case, since it looks like it should work, while example.org perhaps more obviously won't? I'm on the fence here.
Problems with this:
|
Is it possible for us to host a JSON data source ourselves, a la typicode style, but with the right CSP configured on d.m.o.? Alternatively make d.m.o. accept typicode. |
We could, but not in content of course. Also I wonder whether this site is better than https://httpbin.org/, which is what I generally use for testing. |
MDN URL
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
What specific section or headline is this issue about?
Fetch Basic Sample Code
What information was incorrect, unhelpful, or incomplete?
The first sample given for fetch:
results in a json parse error, since the sample url returns a 404.
Recommend a sample URL which will return 200 status and sample json, such as 'https://jsonplaceholder.typicode.com/users':
What did you expect to see?
A successfully parsed JSON object printed to the console. This is the most basic example provided, from the source reference itself, and it should result in an error free response when copied & pasted.
Do you have any supporting links, references, or citations?
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
Do you have anything more you want to share?
No response
MDN metadata
Page report details
en-us/web/api/fetch_api/using_fetch
The text was updated successfully, but these errors were encountered: