Home
Explore
Exams
Login
Get started
Home
Asynchrony, HTTP/JSON, Fetch, and forms
Asynchrony, HTTP/JSON, Fetch, and forms
0.0
(0)
Rate it
Studied by 0 people
Call Kai
Learn
Practice Test
Spaced Repetition
Match
Flashcards
Knowt Play
Card Sorting
1/17
There's no tags or description
Looks like no tags are added yet.
18 Terms
View all (18)
Star these 18
1
New cards
How do synchronous statements run, and what happens with async work?
Synchronous statements run in sequence. Async work continues later.
2
New cards
What states can a Promise be in?
It starts pending, then is fulfilled or rejected, once.
3
New cards
What does .then do?
It transforms fulfilled values.
4
New cards
What does .catch do?
It handles rejection.
5
New cards
What does an async function return?
A Promise.
6
New cards
What does await pause?
The async function, not the browser.
7
New cards
GET vs. POST: what is each commonly used for?
GET reads. POST commonly sends new data.
8
New cards
What do HTTP status codes 2xx, 4xx, and 5xx mean?
2xx = success, 4xx = request (client) error, 5xx = server error.
9
New cards
What are the formatting rules for JSON?
It is text with double-quoted property names and string values.
10
New cards
What can JSON NOT contain?
Functions or undefined.
11
New cards
What does fetch(url) resolve to, even for many 404/500 replies?
A Response object. It does not reject on those errors.
12
New cards
How do you check that a fetch request succeeded?
Check response.ok.
13
New cards
What does response.json() return?
Another Promise, so you must await or .then it.
14
New cards
What method does a normal HTML form use by default?
GET, unless method is set.
15
New cards
What does a form's action attribute specify, and how are query values sent?
It specifies the destination. Query values are URL encoded.
16
New cards
What are the 3 steps to send a form with JS instead of the default submit?
1. A submit listener calls event.preventDefault() 2. Collect inputs with FormData 3. Send a POST
17
New cards
How do you send JSON in a POST request?
Set Content-Type: application/json and send JSON.stringify(payload) as the body.
18
New cards
How do you send FormData in a POST, and what should you NOT do?
Pass it directly as the body. Do not manually set the multipart Content-Type, because the browser adds the boundary itself.