WhatsApp us

How to use AJAX in PHP with example

  • Tech Area
  • Last updated on: January 8, 2026



AJAX stands for Asynchronous JavaScript and XML. AJAX is a technology that reduces the interactions between the server and client. It is a technique for creating better, faster, and more interactive web applications. The main purpose of AJAX technology is to exchange small amounts of data with server without page refresh. With AJAX when submit is pressed, JavaScript will make a request to the server, interpret the results and update the current screen.

JavaScript is a client side scripting language. It is executed on the client side by the web browsers that support JavaScript.

XML is the acronym for Extensible Markup Language. It is used to encode messages in both human and machine readable formats.

Files used in this tutorial:

1- index.php

2- read.php

Below are the step by step process of how to use ajax in PHP.

Step 1: Create index.php file

index.php

<script src="https://code.jquery.com/jquery-3.7.1.js"></script>
<input type="text" id="text1">
<a href='#' onclick="on_click()">Click Me</a>

<script type="text/javascript">
	function on_click(){
		var val = $('#text1').val();
		$.ajax({
			url: 'read.php',
			method: 'post',
			data: 'Data='+val,
			success: function(data){
				alert(data);
			}
		});
	}
</script>

Step 2: Create read.php file

read.php

<?php
echo $_POST['Data'];
?>

Output


Subscribe us via Email

Join 20,000+ subscriber

Subscribe on YouTube

PHP Projects
Matrimonial Portal Project in PHP & MySQL Last Updated: December 22, 2025
Event Management System Project in PHP & MySQL Last Updated: December 6, 2025
Online Shopping System Project in PHP MySQL Last Updated: November 26, 2025
Hostel management system project in PHP and MySQL Last Updated: February 14, 2024
Online Pizza Delivery project in PHP Last Updated: February 4, 2024
Parking Management System project in PHP Last Updated: November 5, 2023
Visitors Management System project in PHP Last Updated: August 28, 2023
SNIPE – IT Asset management system v6.1.0 Last Updated: April 21, 2023
Employee Management System project in PHP Last Updated: January 21, 2023