jQuery AJAX GET Element
Prerequisites
Objectives
Make HTTP requests using curl
, the browser address bar, and AJAX for:
Use response data in future requests
Preparation
- Fork and clone
this repository.
- Create and checkout a new branch (training).
- Install dependencies with
npm install
.
You can access the same web server that we set up during jquery-ajax-get-collection. Just leave the server running at the same port.
If you need to set up the web server from scatch:
We'll make requests of and receive responses from an HTTP server we'll set up
together:
- Open a new terminal (window or tab).
- Change into
~/wdi/tmp
.
- Fork and clone library-api-guide
and follow installation instructions listed there.
- Once installed, checkout a
jquery-ajax
branch within library-api
.
We're now ready to make requests.
GET /books/:id
Retrieve a book from the API
Demo: Browser Single Book
Entering http://localhost:4741/books/1
into the chrome address bar.
Demo: Curl Single Book
We'll use curl to retrieve the one book at a time.
Code Along: Curl Single Book
Let's write that curl command into a script.
Lab: AJAX Single Book
Again, take a stepped approach:
- Add a text input for a book id to the form in
index.html
.
- Retrieve the value of the id, if any, in the submit handler.
- Branch on that value in the submit handler.
- Add a single book success and fail handler to
assets/scripts/ui.js
.
- Add a single book retrieval method to
assets/scripts/library-api.js
.
- Invoke the single book retrieval method from the submit handler passing the
success and fail callbacks.
- All content is licensed under a CCBYNCSA 4.0 license.
- All software code is licensed under GNU GPLv3. For commercial use or
alternative licensing, please contact legal@ga.co.