AJAX, Fetch, and Promises
CSCI 344: Advanced Web Technologies
Spring 2025
Outline
Intro to “AJAX”
AJAX
3
Intro to Fetch
JavaScript’s Fetch API
4
What is a Promise?
Most requests happen in 2 Parts (w/2 Promises)
async function getData () {
const response = await fetch(url);
const data = await response.json();
}
Promises: Two Syntaxes > “then” method
Using the promise’s “then” method, which will execute a callback function when the promise finishes its business...�
let url = 'https://www.apitutor.org/yelp/simple/v3/businesses/search?location=Asheville,+NC'
fetch(url)
.then(response => response.json()) // callback function
.then(data => console.log(data)); // callback function
2. Promises: Two Syntaxes > async await
Using the async / await technique. Instead of using “then()” the await keyword ensures that the next line doesn’t execute until the promise resolves.
const getPosts = async () => {
let url = 'https://www.apitutor.org/yelp/simple/v3/businesses/search?location=Asheville,+NC';
const response = await fetch(url);
console.log(response);
const jsonData = await response.json();
console.log(jsonData);
};
getPosts();
Sample files
Let’s take a look at the Lecture 15 sample files to process these ideas…
Outline
Summary (1 of 2)
Summary (2 of 2)
When we come back from break
Read the Homework 3 Instructions �before coming to class