i

PHP Tutorial

AJAX PHP

In PHP, we use AJAX to make our webpage or website more interactive. For example, if we are getting input like user id and users are allowed to keep any name, then we can use AJAX to suggest some attractive and unique names to them. Similarly, if we want to allow users to enter their favorite language, then we can allow a few popular programming languages as a suggestion to them.

The web page will communicate with a web server when a user types a character in the input field and will respond immediately based on the input value.

Example: Suppose we create a form in HTML with an input field mentioning – Preferred Programming Language and a text field as below.

We will create a function that is triggered by the onkeyup event that shows the suggestions. The code for the HTML script will be: