AJAX tutorial

Update pages with data from the server, without reloading

About this tutorial

AJAX lets a web page talk to the server in the background: search results appear as you type, comments post without a page reload, and dashboards update by themselves.

In this beginner class you learn JSON, promises and async/await, then send and receive data with fetch() and jQuery, build PHP endpoints that return JSON, and finish with a live comment wall backed by MySQL. You should know JavaScript and basic PHP first. Every lesson has examples, an exercise and a quiz.

Lessons

Getting started

  1. What is AJAX?How pages request data in the background, what requests and responses are, and setting up a local server to practise. Free 3 min
  2. JSON: the language of dataWrite JSON correctly, convert between JSON and JavaScript, and create JSON in PHP. Free 12 min

Asynchronous JavaScript

  1. Callbacks, promises and async/awaitUnderstand code that finishes later, and handle it with callbacks, promises and async/await. Locked 20 min
  2. Your first fetch() requestLoad a JSON file with fetch(), check the response, read the JSON and show it on the page. Locked 17 min
  3. Loading states and errorsShow a loading message, disable buttons while waiting, and give friendly messages when something goes wrong. Locked 24 min

Talking to PHP

  1. A PHP endpoint that returns JSONWrite PHP files that answer AJAX requests with JSON, read query parameters and send the right status codes. Locked 17 min
  2. Sending data with POSTSend form data and JSON to PHP with fetch, read it on the server, validate it and reply with JSON. Locked 21 min
  3. AJAX with jQueryMake the same requests with $.getJSON, $.post and $.ajax, and handle success and errors the jQuery way. Locked 16 min
  4. Live searchSearch a MySQL table as the visitor types, with a debounce, a PDO LIKE query and safely rendered results. Locked 21 min
  5. Keeping AJAX secureProtect endpoints with sessions, CSRF tokens, server-side validation and safe output. Locked 9 min

Project and review

  1. Project: a live comment wallBuild a comment wall that loads, posts and refreshes comments without reloading, with PHP, MySQL and fetch. Locked 25 min
  2. AJAX final quizFifteen questions covering the whole AJAX beginner class. Score yourself to finish the course. Locked 6 min
Hi there! đź‘‹ Have a question about the courses or joining the class? Ask me.