SlideShare a Scribd company logo
Ajax
What is AJAX?
AJAX stands for “Asynchronous Javascript and XML”. It isn’t a single, nor a new technology. In
fact, it is a group of existing technologies (i.e. HTML, CSS, Javascript, XML, etc.) which come
together to build modern web applications.
With AJAX, a client (i.e. browser) communicates with a web server and asks for data. Then, it
processes the server’s response and make changes to the page without fully reloading it.
Let’s break down the AJAX acronym:
 “Asynchronous” means that when a client requests data from a web server, it
doesn’t freeze until the server replies. On the contrary, the user can still navigate the
pages. As soon as the server returns a response, a relevant function manipulates the
returned data behind the scenes.
 “Javascript” is the language which instantiates an AJAX request, parses the
corresponding AJAX response, and finally updates the DOM.
 A client uses the XMLHttpRequest or XHR API to make a request to a server.
Think of the API (Application Programming Interface) as a set of methods which specify
the rules of communication between the two interested parties. However, note that the
incoming data from an AJAX request can be in any format and not only
in XML format.
How AJAX Works
To get an initial idea of how AJAX works, take a look at the following visualization:
This visualization describes a typical AJAX-driven scenario:
 The user wants to see more articles, so he or she clicks on the target button. This
event triggers an AJAX call.
 A request is sent to the server. Along with the request, different data may be
passed. The request can point to a static file (e.g. example.json ) which is stored on the
server. Alternatively, it’s possible to execute a dynamic script (e.g. functions.php ) at
which point the script talks to the database (or other system) to retrieve data.
 The database sends back the requested articles to the server. Next, the server
sends them to the browser.
 JavaScript parses the response and updates specific parts of the DOM (the page
structure). Here, for instance, only the sidebar is being updated. The other parts of the
page don’t change.
With this in mind, you can understand why AJAX is an important concept for modern web. By
developing AJAX-powered applications, we’re able to control the amount of data that is
downloaded from the server.
Ajax First Program with Explanation
Firstprogram.html
<html>
<head>
<script type="text/javascript">
function fun1()
{
var a;
if (window.XMLHttpRequest)
{// If the browser if IE7+[or]Firefox[or]Chrome[or]Opera[or]Safari
a=new XMLHttpRequest();
}
else
{//If browser is IE6, IE5
a=new ActiveXObject("Microsoft.XMLHTTP");
}
a.onreadystatechange=function()
{
if (a.readyState==4 && a.status==200)
{
document.getElementById("myDiv").innerHTML=a.responseText;
}
}
a.open("POST","Sample.txt",true);
a.send();
} // fun1() close
</script>
</head>
<body>
<div id="myDiv" style="width: 300px; height: 30px;">Click on the button below</div>
<button type="button" onclick="fun1()">Change Content</button>
</body>
</html>
Sample.txt
Welcome to IT Department.
Explanation
 Once the document loaded then immediately we will be able to see one button Change
Content , and see i have been given onclick=”fun1()” [ line number 33 ] means once we click
on this button controller will go to line number 4 and will starts execute that fun1()
 At line number 6, i have taken one variable with name a
 For any ajax program, we must create one request object to send our ajax request to the server,
that ajax object is nothing but XMLHttpRequest object
 See line number 8, i have written window.XMLHttpRequest means am checking whether my
browser supports XMLHttpRequest object or not, if yes assigning XMLHttpRequest object into
a [ a=new XMLHttpRequest(); ] else i mean if our web browser doesnt
supports XMLHttpRequest object then we can assign ActiveXObject [ which supports old web
browsers ] into our variable a [ a=new ActiveXObject(“Microsoft.XMLHTTP”); ]
 So from line numbers 8 -15 request object creation work been done
 Now controller directly jumps to line number 25, and opens the connection and send the request
to sample.txt (this is my notepad file), see actually the 3rd parameter i have given as true means
Asynchronous data transfer will be activated
 Finally request will be sent in line number 26, that’s it.
 If server sends the response back to our application then controller will automatically execute
from line number 17 – 23, you may get one doubt like why its not executed initially… ? there is
a reason actually this a.onreadystatechange=function() executes only when we get the response
from the server.

More Related Content

PPT
PHP - Introduction to PHP AJAX
PPT
PPT
PDF
Introduction to ajax
PPT
Ajax Presentation
PPTX
Introduction to ajax
PHP - Introduction to PHP AJAX
Introduction to ajax
Ajax Presentation
Introduction to ajax

What's hot (20)

PPT
Ajax and PHP
PPT
Ajax Introduction
PPTX
Ajax and Jquery
PPT
Ajax Presentation
PPT
2310 b 12
PPT
PDF
PPTX
Node js crash course session 6
PPT
PPTX
Suga ajax training
PPTX
Node js crash course session 5
PPTX
Introduction to JSON & AJAX
PDF
Ajax chap 2.-part 1
PDF
Ajax chap 3
PPTX
XAML Data Binding in UWP
PDF
FOXX - a Javascript application framework on top of ArangoDB
PPT
Grails Controllers
PPT
Ajax and PHP
Ajax Introduction
Ajax and Jquery
Ajax Presentation
2310 b 12
Node js crash course session 6
Suga ajax training
Node js crash course session 5
Introduction to JSON & AJAX
Ajax chap 2.-part 1
Ajax chap 3
XAML Data Binding in UWP
FOXX - a Javascript application framework on top of ArangoDB
Grails Controllers
Ad

Similar to Ajax.pdf (20)

TXT
25250716 seminar-on-ajax text
PPT
PPT
Asynchronous JavaScript & XML (AJAX)
PPT
Ajax Introduction
PPT
Mashup
PPT
PPT
DOCX
Copy of ajax tutorial
PPT
AJAX
PDF
1 ppt-ajax with-j_query
PPTX
Introduction about-ajax-framework
PDF
M6 l8-ajax-handout
PPT
Ajax tutorial by bally chohan
25250716 seminar-on-ajax text
Asynchronous JavaScript & XML (AJAX)
Ajax Introduction
Mashup
Copy of ajax tutorial
AJAX
1 ppt-ajax with-j_query
Introduction about-ajax-framework
M6 l8-ajax-handout
Ajax tutorial by bally chohan
Ad

More from Rajkiran Mummadi (17)

PPTX
PDF
Javabeans .pdf
PPTX
Java beans
PPTX
Java script
PPTX
Google glasses
PPTX
Environmental hazards
PDF
Wcharging
PPTX
Wireless charging
PPTX
Standard bop
PPTX
Russian technology in indian banking system 1
PPT
Ai presentation
PPTX
PPT
autonomous cars
PPTX
demonetisation
Javabeans .pdf
Java beans
Java script
Google glasses
Environmental hazards
Wcharging
Wireless charging
Standard bop
Russian technology in indian banking system 1
Ai presentation
autonomous cars
demonetisation

Recently uploaded (20)

PPTX
TLE Review Electricity (Electricity).pptx
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Spectroscopy.pptx food analysis technology
PDF
Encapsulation theory and applications.pdf
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PPTX
OMC Textile Division Presentation 2021.pptx
PPT
Teaching material agriculture food technology
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Tartificialntelligence_presentation.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
cloud_computing_Infrastucture_as_cloud_p
PPTX
1. Introduction to Computer Programming.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PPTX
Machine Learning_overview_presentation.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
TLE Review Electricity (Electricity).pptx
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Spectroscopy.pptx food analysis technology
Encapsulation theory and applications.pdf
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
OMC Textile Division Presentation 2021.pptx
Teaching material agriculture food technology
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Unlocking AI with Model Context Protocol (MCP)
Tartificialntelligence_presentation.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
cloud_computing_Infrastucture_as_cloud_p
1. Introduction to Computer Programming.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Group 1 Presentation -Planning and Decision Making .pptx
Machine Learning_overview_presentation.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
SOPHOS-XG Firewall Administrator PPT.pptx

Ajax.pdf

  • 1. Ajax What is AJAX? AJAX stands for “Asynchronous Javascript and XML”. It isn’t a single, nor a new technology. In fact, it is a group of existing technologies (i.e. HTML, CSS, Javascript, XML, etc.) which come together to build modern web applications. With AJAX, a client (i.e. browser) communicates with a web server and asks for data. Then, it processes the server’s response and make changes to the page without fully reloading it. Let’s break down the AJAX acronym:  “Asynchronous” means that when a client requests data from a web server, it doesn’t freeze until the server replies. On the contrary, the user can still navigate the pages. As soon as the server returns a response, a relevant function manipulates the returned data behind the scenes.  “Javascript” is the language which instantiates an AJAX request, parses the corresponding AJAX response, and finally updates the DOM.  A client uses the XMLHttpRequest or XHR API to make a request to a server. Think of the API (Application Programming Interface) as a set of methods which specify the rules of communication between the two interested parties. However, note that the incoming data from an AJAX request can be in any format and not only in XML format. How AJAX Works To get an initial idea of how AJAX works, take a look at the following visualization: This visualization describes a typical AJAX-driven scenario:
  • 2.  The user wants to see more articles, so he or she clicks on the target button. This event triggers an AJAX call.  A request is sent to the server. Along with the request, different data may be passed. The request can point to a static file (e.g. example.json ) which is stored on the server. Alternatively, it’s possible to execute a dynamic script (e.g. functions.php ) at which point the script talks to the database (or other system) to retrieve data.  The database sends back the requested articles to the server. Next, the server sends them to the browser.  JavaScript parses the response and updates specific parts of the DOM (the page structure). Here, for instance, only the sidebar is being updated. The other parts of the page don’t change. With this in mind, you can understand why AJAX is an important concept for modern web. By developing AJAX-powered applications, we’re able to control the amount of data that is downloaded from the server. Ajax First Program with Explanation Firstprogram.html <html> <head> <script type="text/javascript"> function fun1() { var a; if (window.XMLHttpRequest) {// If the browser if IE7+[or]Firefox[or]Chrome[or]Opera[or]Safari a=new XMLHttpRequest(); } else {//If browser is IE6, IE5 a=new ActiveXObject("Microsoft.XMLHTTP"); } a.onreadystatechange=function() { if (a.readyState==4 && a.status==200) {
  • 3. document.getElementById("myDiv").innerHTML=a.responseText; } } a.open("POST","Sample.txt",true); a.send(); } // fun1() close </script> </head> <body> <div id="myDiv" style="width: 300px; height: 30px;">Click on the button below</div> <button type="button" onclick="fun1()">Change Content</button> </body> </html> Sample.txt Welcome to IT Department. Explanation  Once the document loaded then immediately we will be able to see one button Change Content , and see i have been given onclick=”fun1()” [ line number 33 ] means once we click on this button controller will go to line number 4 and will starts execute that fun1()  At line number 6, i have taken one variable with name a  For any ajax program, we must create one request object to send our ajax request to the server, that ajax object is nothing but XMLHttpRequest object  See line number 8, i have written window.XMLHttpRequest means am checking whether my browser supports XMLHttpRequest object or not, if yes assigning XMLHttpRequest object into a [ a=new XMLHttpRequest(); ] else i mean if our web browser doesnt supports XMLHttpRequest object then we can assign ActiveXObject [ which supports old web browsers ] into our variable a [ a=new ActiveXObject(“Microsoft.XMLHTTP”); ]  So from line numbers 8 -15 request object creation work been done
  • 4.  Now controller directly jumps to line number 25, and opens the connection and send the request to sample.txt (this is my notepad file), see actually the 3rd parameter i have given as true means Asynchronous data transfer will be activated  Finally request will be sent in line number 26, that’s it.  If server sends the response back to our application then controller will automatically execute from line number 17 – 23, you may get one doubt like why its not executed initially… ? there is a reason actually this a.onreadystatechange=function() executes only when we get the response from the server.