AJAX (Partie 4) - Réponse CGI (exemple de saisie automatique ou autocomplete)

13 Sept 2020 · 13 min
12:50

In this French tutorial, the instructor demonstrates how to build a real‑time autocomplete feature using AJAX with a PHP CGI backend. After reviewing previous lessons on creating an AJAX instance and handling text/XML responses, the video shifts to generating server responses via a PHP script. The client side consists of an `autocomplete.html` page that captures user input in a text field and sends it to `contenu.php` using an `XMLHttpRequest` triggered on the `onkeyup` event. The request is sent via POST with the `Content-Type: application/x-www-form-urlencoded` header, encoding the typed word as the `mot` parameter. On the server, `contenu.php` includes a PDO connection (`connexion.php`), prepares a SELECT query on a `Glossaire` table, uses a `LIKE` pattern with a leading `%` and `trim` to match entries that start with the user’s input, and fetches results as an associative array. The results are wrapped in `<div>` elements and returned as plain text. The client script receives the response, injects the HTML into a suggestion container (`sug`), and toggles its visibility with CSS (`visibility: hidden/visible`) based on whether there are matches and whether the input field is empty. Finally, a click handler is added to each suggestion div: clicking a suggestion copies its text into the input field using `event.target.textContent`. The tutorial walks through each step, testing in the browser, debugging, and refining the UI, concluding that AJAX can retrieve dynamically generated CGI responses to power an autocomplete system.

Chapters

More from Yamossoun

8:56
youtube.com

Compteur synchrone - Logique séquentielle

2w ago
11:58
youtube.com

Compteur asynchrone et diviseur de fréquence - Logique séquentielle

3w ago
11:37
youtube.com

Les registres (parallèle et à décalage) - Logique séquentielle

1mo ago
6:14
youtube.com

Bascule T (Toggle) - Logique séquentielle

1mo ago
12:05
youtube.com

Bascule JK - Logique séquentielle

1mo ago
9:17
youtube.com

Bascule D flip-flop active sur front montant - Logique séquentielle

1mo ago
10:08
youtube.com

Bascule D Latch - Logique séquentielle

1mo ago
8:13
youtube.com

Bascule RS - Logique séquentielle

1mo ago
5:04
youtube.com

Logique séquentielle - Introduction

2mo ago
1:15
youtube.com

Le codeur - Logique combinatoire #codeur #logique #circuit #booleanlogic

2mo ago
1:56
youtube.com

Algorithme de calcule de la racine carrée par dichotomie #dichotomy #squareroot #algorithm

3mo ago
See all content