From the course: JavaScript: Ajax and Fetch
Unlock this course with a free trial
Join today to access over 25,600 courses taught by industry experts.
Work with JSON data - JavaScript Tutorial
From the course: JavaScript: Ajax and Fetch
Work with JSON data
After you receive the response from your Ajax request, you have to dig into it and find the specific data you need. JavaScript Object Notation, or JSON, is by far the most common format used to exchange data on the modern web. JSON data is transmitted as a string, so in general, the first thing you need to do is parse it into the data format it encodes. Although the word object is in the name, JSON data could parse out as either an object or an array, which is technically just another type of object in JavaScript. To parse a JSON string, you use the parse method of the JSON object, which is built into JavaScript. However, the basic structure of a fetch request takes care of the parsing for you, so you don't actually need to use the JSON.parse command. In my create request function, I pass the API response to my handle errors function, and the first line of that function passes the data from a successful response through the response JSON method, which returns an object or an array. So…
Contents
-
-
-
-
-
What is the DOM?2m 45s
-
Select elements with vanilla JavaScript3m
-
(Locked)
Request data in response to an event5m 8s
-
(Locked)
Add an event listener2m 13s
-
(Locked)
Work with JSON data4m 31s
-
(Locked)
Modify form values with vanilla JavaScript4m 39s
-
(Locked)
Modify element content with vanilla JavaScript4m 14s
-
(Locked)
Challenge: Modify the DOM52s
-
(Locked)
Solution: Modify the DOM6m 29s
-
-
-
-