Skip to content

Instantly share code, notes, and snippets.

View aarikpokras's full-sized avatar

Aarik Pokras aarikpokras

View GitHub Profile
@aarikpokras
aarikpokras / js_get_requests.md
Last active February 14, 2024 21:42
JavaScript Fetching with Fetch and XHR

Getting pages in JavaScript

Fetch

JSON

To get JSON content, you need to use the response JSON type, which isn't quite difficult to use. To fetch https://con-se.glitch.me/res/searchme.json, here's what you would do initially:

fetch('https://con-se.glitch.me/res/searchme.json')

But now all you have is a promise, no actual content. Here's where the then function comes in. You'll need two:

 .then(response => response.json())