SlideShare a Scribd company logo
2
Most read
4
Most read
5
Most read
www.webstackacademy.com
AJAX
jQuery
www.webstackacademy.com
Introduction to AJAX
• AJAX(Asynchronous JavaScript and XML) is a mechanism of performing data exchange
with the server without reloading the whole code
• It helps to fetch data in form of XML / JSON / HTML
• With vanilla JavaScript, writing AJAX code is quite complex where you need to write
multiple lines of code
• With jQuery you can perform it very easily
www.webstackacademy.com
Example usage – Vanilla JavaScript code
<script>
function loadDoc() {
// Create a request object
var xhttp = new XMLHttpRequest();
// Register the function to be called when server responds
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML = this.responseText;
}
};
// There is a file called ajax_info.txt on server
xhttp.open("GET", "ajax_info.txt", true);
// Send the request
xhttp.send();
}
</script>
www.webstackacademy.com
jQuery AJAX APIs
API & Description
$(selector).load(URL,data,callback);
Sets or returns the text content of selected elements
• URL - The location from where data need to be fetched
• data - Query string
• callback - To get notification when the load is complete
The callback function can further have three parameters:
• responseTxt - contains the resulting content if the call succeeds
• statusTxt - contains the status of the call
• xhr - contains the XMLHttpRequest object
www.webstackacademy.com
Example usage – Loading URL contents
<script>
$(document).ready(function() {
$("button").click(function() {
/* Load a page from external URL with response / error handling */
$("#div1").load("http://jsonplaceholder.typicode.com/posts/1",
function(responseTxt, statusTxt, xhr){
if(statusTxt == "success")
alert("External content loaded successfully!");
if(statusTxt == "error")
alert("Error: " + xhr.status + ": " + xhr.statusText);
});
});
});
</script>
www.webstackacademy.com
jQuery AJAX APIs
Selector Description
$.get(URL,callback); URL - The location from where data need to be fetched
callback - To get notification when the load is complete
$.post(URL,data,callback); URL - The location from where data need to be fetched
data - That required to be posted
callback - To get notification when the load is complete
www.webstackacademy.com
Example usage – HTTP GET
<script>
$(document).ready(function() {
$("button").click(function() {
$.get("https://api.github.com/users/devendradora",
function(data, status){
console.log("Data: " , data , "nStatus: " , status);
});
});
});
</script>
www.webstackacademy.com
WebStack Academy
#83, Farah Towers,
1st Floor, MG Road,
Bangalore – 560001
M: +91-809 555 7332
E: training@webstackacademy.com
WSA in Social Media:

More Related Content

PDF
jQuery - Chapter 4 - DOM Handling
PDF
jQuery - Chapter 3 - Effects
PDF
jQuery -Chapter 2 - Selectors and Events
PDF
jQuery - Chapter 1 - Introduction
PDF
JavaScript - Chapter 7 - Advanced Functions
PPT
Java script
PDF
JavaScript - Chapter 8 - Objects
PDF
jQuery Effects
jQuery - Chapter 4 - DOM Handling
jQuery - Chapter 3 - Effects
jQuery -Chapter 2 - Selectors and Events
jQuery - Chapter 1 - Introduction
JavaScript - Chapter 7 - Advanced Functions
Java script
JavaScript - Chapter 8 - Objects
jQuery Effects

What's hot (20)

PPT
JavaScript JQUERY AJAX
PPT
J query
PPTX
J query1
PPT
Java script -23jan2015
PDF
JavaScript 101
PPTX
jQuery
PDF
Introduzione JQuery
PPT
jQuery for beginners
PDF
Web 6 | JavaScript DOM
PDF
Object Oriented PHP - PART-2
PPT
JQuery introduction
PPTX
jQuery PPT
PPT
Java Script ppt
PDF
AngularJS Basics with Example
PPTX
JavaScript and jQuery Basics
PDF
Difference between java script and jquery
PPTX
Jqueryppt (1)
PPT
9781305078444 ppt ch12
PPTX
Java script basics
PDF
Web 5 | JavaScript Events
JavaScript JQUERY AJAX
J query
J query1
Java script -23jan2015
JavaScript 101
jQuery
Introduzione JQuery
jQuery for beginners
Web 6 | JavaScript DOM
Object Oriented PHP - PART-2
JQuery introduction
jQuery PPT
Java Script ppt
AngularJS Basics with Example
JavaScript and jQuery Basics
Difference between java script and jquery
Jqueryppt (1)
9781305078444 ppt ch12
Java script basics
Web 5 | JavaScript Events
Ad

Similar to jQuery - Chapter 5 - Ajax (20)

PPT
Ajax.ppt
PPTX
Unit-5.pptx
PPT
J query 01.07.2013.html
PPT
J query 01.07.2013
PPTX
AJAX.pptx
PPT
PPT
PPTX
Ajax for dummies, and not only.
PPTX
Ajax
PDF
Ajax and xml
PPT
Xml http request
PDF
Core Java tutorial at Unit Nexus
PDF
Ajax chap 5
PPT
Ajax Tuturial
PPT
Ajax Lecture Notes
PPTX
Web-Engineering-Lec-14 (1) .pptx
PPTX
Web-Engineering-Lec-14 (1 ).pptx
PPT
AJAX.ppt
PPT
AJAX Workshop Notes
Ajax.ppt
Unit-5.pptx
J query 01.07.2013.html
J query 01.07.2013
AJAX.pptx
Ajax for dummies, and not only.
Ajax
Ajax and xml
Xml http request
Core Java tutorial at Unit Nexus
Ajax chap 5
Ajax Tuturial
Ajax Lecture Notes
Web-Engineering-Lec-14 (1) .pptx
Web-Engineering-Lec-14 (1 ).pptx
AJAX.ppt
AJAX Workshop Notes
Ad

More from WebStackAcademy (20)

PDF
Webstack Academy - Course Demo Webinar and Placement Journey
PDF
WSA: Scaling Web Service to Handle Millions of Requests per Second
PDF
WSA: Course Demo Webinar - Full Stack Developer Course
PDF
Career Building in AI - Technologies, Trends and Opportunities
PDF
Webstack Academy - Internship Kick Off
PDF
Building Your Online Portfolio
PDF
Front-End Developer's Career Roadmap
PDF
Angular - Chapter 9 - Authentication and Authorization
PDF
Angular - Chapter 7 - HTTP Services
PDF
Angular - Chapter 6 - Firebase Integration
PDF
Angular - Chapter 5 - Directives
PDF
Angular - Chapter 4 - Data and Event Handling
PDF
Angular - Chapter 3 - Components
PDF
Angular - Chapter 2 - TypeScript Programming
PDF
Angular - Chapter 1 - Introduction
PDF
JavaScript - Chapter 10 - Strings and Arrays
PDF
JavaScript - Chapter 15 - Debugging Techniques
PDF
JavaScript - Chapter 14 - Form Handling
PDF
JavaScript - Chapter 13 - Browser Object Model(BOM)
PDF
JavaScript - Chapter 12 - Document Object Model
Webstack Academy - Course Demo Webinar and Placement Journey
WSA: Scaling Web Service to Handle Millions of Requests per Second
WSA: Course Demo Webinar - Full Stack Developer Course
Career Building in AI - Technologies, Trends and Opportunities
Webstack Academy - Internship Kick Off
Building Your Online Portfolio
Front-End Developer's Career Roadmap
Angular - Chapter 9 - Authentication and Authorization
Angular - Chapter 7 - HTTP Services
Angular - Chapter 6 - Firebase Integration
Angular - Chapter 5 - Directives
Angular - Chapter 4 - Data and Event Handling
Angular - Chapter 3 - Components
Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 1 - Introduction
JavaScript - Chapter 10 - Strings and Arrays
JavaScript - Chapter 15 - Debugging Techniques
JavaScript - Chapter 14 - Form Handling
JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 12 - Document Object Model

Recently uploaded (20)

PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Big Data Technologies - Introduction.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
DOCX
The AUB Centre for AI in Media Proposal.docx
Dropbox Q2 2025 Financial Results & Investor Presentation
Understanding_Digital_Forensics_Presentation.pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Encapsulation_ Review paper, used for researhc scholars
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Chapter 3 Spatial Domain Image Processing.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
The Rise and Fall of 3GPP – Time for a Sabbatical?
Mobile App Security Testing_ A Comprehensive Guide.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Big Data Technologies - Introduction.pptx
MIND Revenue Release Quarter 2 2025 Press Release
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Review of recent advances in non-invasive hemoglobin estimation
The AUB Centre for AI in Media Proposal.docx

jQuery - Chapter 5 - Ajax

  • 2. www.webstackacademy.com Introduction to AJAX • AJAX(Asynchronous JavaScript and XML) is a mechanism of performing data exchange with the server without reloading the whole code • It helps to fetch data in form of XML / JSON / HTML • With vanilla JavaScript, writing AJAX code is quite complex where you need to write multiple lines of code • With jQuery you can perform it very easily
  • 3. www.webstackacademy.com Example usage – Vanilla JavaScript code <script> function loadDoc() { // Create a request object var xhttp = new XMLHttpRequest(); // Register the function to be called when server responds xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { document.getElementById("demo").innerHTML = this.responseText; } }; // There is a file called ajax_info.txt on server xhttp.open("GET", "ajax_info.txt", true); // Send the request xhttp.send(); } </script>
  • 4. www.webstackacademy.com jQuery AJAX APIs API & Description $(selector).load(URL,data,callback); Sets or returns the text content of selected elements • URL - The location from where data need to be fetched • data - Query string • callback - To get notification when the load is complete The callback function can further have three parameters: • responseTxt - contains the resulting content if the call succeeds • statusTxt - contains the status of the call • xhr - contains the XMLHttpRequest object
  • 5. www.webstackacademy.com Example usage – Loading URL contents <script> $(document).ready(function() { $("button").click(function() { /* Load a page from external URL with response / error handling */ $("#div1").load("http://jsonplaceholder.typicode.com/posts/1", function(responseTxt, statusTxt, xhr){ if(statusTxt == "success") alert("External content loaded successfully!"); if(statusTxt == "error") alert("Error: " + xhr.status + ": " + xhr.statusText); }); }); }); </script>
  • 6. www.webstackacademy.com jQuery AJAX APIs Selector Description $.get(URL,callback); URL - The location from where data need to be fetched callback - To get notification when the load is complete $.post(URL,data,callback); URL - The location from where data need to be fetched data - That required to be posted callback - To get notification when the load is complete
  • 7. www.webstackacademy.com Example usage – HTTP GET <script> $(document).ready(function() { $("button").click(function() { $.get("https://api.github.com/users/devendradora", function(data, status){ console.log("Data: " , data , "nStatus: " , status); }); }); }); </script>
  • 8. www.webstackacademy.com WebStack Academy #83, Farah Towers, 1st Floor, MG Road, Bangalore – 560001 M: +91-809 555 7332 E: training@webstackacademy.com WSA in Social Media: