Ajax Intro in Jquery
What is AJAX?
AJAX stands for:
Asynchronous JavaScript And XML
It allows your web page to send and receive data from a server — without reloading the whole page!
? Why Use AJAX?
With AJAX, you can:
? Submit a form without refreshing the page
? Load data from the server in real time
? Update part of a page dynamically
? Build fast and responsive websites
? What is jQuery AJAX?
jQuery provides simple methods to perform AJAX operations, such as:
| Method | Description |
|---|---|
$.get() | Send a GET request |
$.post() | Send a POST request |
$.ajax() | Full control (method, data, etc.) |
These methods help you communicate with the server using JavaScript.
? Example: AJAX with jQuery
? HTML
<button id="loadBtn">Load Message</button><div id="result"></div>
? message.php
<?phpecho "Hello from the server!";?>
? jQuery AJAX Code
$("#loadBtn").click(function() { $.get("message.php", function(data) { $("#result").html(data); // Show response in the <div> });});
? When you click the button, it loads content from the server without refreshing the page.
? Common Use Cases
Live search
Dependent dropdowns (country ? state)
Chat/message loading
Submitting forms without reload
? Summary
| Feature | Benefit |
|---|---|
| No page reload | Faster UX |
| Background calls | Fetch data without interrupting user |
| Easy to use | jQuery makes AJAX beginner-friendly |