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

What's hot

Ajax and PHP
Ajax and PHPAjax and PHP
Ajax and PHP
John Coggeshall
 
Ajax Introduction
Ajax IntroductionAjax Introduction
Ajax Introduction
Oliver Cai
 
Ajax Presentation
Ajax PresentationAjax Presentation
Ajax Presentationronaldmam
 
Json
Json Json
Lec 7
Lec 7Lec 7
Node js crash course session 6
Node js crash course   session 6Node js crash course   session 6
Node js crash course session 6
Abdul Rahman Masri Attal
 
Node js crash course session 5
Node js crash course   session 5Node js crash course   session 5
Node js crash course session 5
Abdul Rahman Masri Attal
 
Introduction to JSON & AJAX
Introduction to JSON & AJAXIntroduction to JSON & AJAX
Introduction to JSON & AJAX
Collaboration Technologies
 
Ajax chap 2.-part 1
Ajax chap 2.-part 1Ajax chap 2.-part 1
Ajax chap 2.-part 1
Mukesh Tekwani
 
Ajax chap 3
Ajax chap 3Ajax chap 3
Ajax chap 3
Mukesh Tekwani
 
XAML Data Binding in UWP
XAML Data Binding in UWPXAML Data Binding in UWP
XAML Data Binding in UWP
Christian Hissibini
 
FOXX - a Javascript application framework on top of ArangoDB
FOXX - a Javascript application framework on top of ArangoDBFOXX - a Javascript application framework on top of ArangoDB
FOXX - a Javascript application framework on top of ArangoDB
ArangoDB Database
 
Grails Controllers
Grails ControllersGrails Controllers
Grails Controllers
NexThoughts Technologies
 

What's hot (20)

Ajax and PHP
Ajax and PHPAjax and PHP
Ajax and PHP
 
Ajax
AjaxAjax
Ajax
 
Ajax Introduction
Ajax IntroductionAjax Introduction
Ajax Introduction
 
Ajax and Jquery
Ajax and JqueryAjax and Jquery
Ajax and Jquery
 
Ajax Presentation
Ajax PresentationAjax Presentation
Ajax Presentation
 
2310 b 12
2310 b 122310 b 12
2310 b 12
 
Ajax
AjaxAjax
Ajax
 
Json
Json Json
Json
 
Lec 7
Lec 7Lec 7
Lec 7
 
Node js crash course session 6
Node js crash course   session 6Node js crash course   session 6
Node js crash course session 6
 
Ajax
AjaxAjax
Ajax
 
Suga ajax training
Suga ajax trainingSuga ajax training
Suga ajax training
 
Node js crash course session 5
Node js crash course   session 5Node js crash course   session 5
Node js crash course session 5
 
Introduction to JSON & AJAX
Introduction to JSON & AJAXIntroduction to JSON & AJAX
Introduction to JSON & AJAX
 
Ajax chap 2.-part 1
Ajax chap 2.-part 1Ajax chap 2.-part 1
Ajax chap 2.-part 1
 
Ajax chap 3
Ajax chap 3Ajax chap 3
Ajax chap 3
 
XAML Data Binding in UWP
XAML Data Binding in UWPXAML Data Binding in UWP
XAML Data Binding in UWP
 
FOXX - a Javascript application framework on top of ArangoDB
FOXX - a Javascript application framework on top of ArangoDBFOXX - a Javascript application framework on top of ArangoDB
FOXX - a Javascript application framework on top of ArangoDB
 
Grails Controllers
Grails ControllersGrails Controllers
Grails Controllers
 
Ajax
AjaxAjax
Ajax
 

Similar to Ajax.pdf

25250716 seminar-on-ajax text
25250716 seminar-on-ajax text25250716 seminar-on-ajax text
25250716 seminar-on-ajax text
Kamleshh Chandnani
 
Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)
Adnan Sohail
 
Ajax
AjaxAjax
Ajax
AjaxAjax
AJAX
AJAXAJAX
AJAX
AJAXAJAX
AJAXARJUN
 
1 ppt-ajax with-j_query
1 ppt-ajax with-j_query1 ppt-ajax with-j_query
1 ppt-ajax with-j_query
Fajar Baskoro
 
Introduction about-ajax-framework
Introduction about-ajax-frameworkIntroduction about-ajax-framework
Introduction about-ajax-framework
Sakthi Bro
 
M Ramya
M RamyaM Ramya
M6 l8-ajax-handout
M6 l8-ajax-handoutM6 l8-ajax-handout
M6 l8-ajax-handoutNolboo Kim
 
Ajax tutorial by bally chohan
Ajax tutorial by bally chohanAjax tutorial by bally chohan
Ajax tutorial by bally chohan
WebVineet
 

Similar to Ajax.pdf (20)

Ajax
AjaxAjax
Ajax
 
Ajax.ppt
Ajax.pptAjax.ppt
Ajax.ppt
 
Ajax
AjaxAjax
Ajax
 
25250716 seminar-on-ajax text
25250716 seminar-on-ajax text25250716 seminar-on-ajax text
25250716 seminar-on-ajax text
 
Ajax
AjaxAjax
Ajax
 
Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)
 
Ajax Introduction
Ajax IntroductionAjax Introduction
Ajax Introduction
 
Mashup
MashupMashup
Mashup
 
Ajax
AjaxAjax
Ajax
 
Ajax
AjaxAjax
Ajax
 
Ajax
AjaxAjax
Ajax
 
AJAX
AJAXAJAX
AJAX
 
Copy of ajax tutorial
Copy of ajax tutorialCopy of ajax tutorial
Copy of ajax tutorial
 
AJAX
AJAXAJAX
AJAX
 
Ajax
AjaxAjax
Ajax
 
1 ppt-ajax with-j_query
1 ppt-ajax with-j_query1 ppt-ajax with-j_query
1 ppt-ajax with-j_query
 
Introduction about-ajax-framework
Introduction about-ajax-frameworkIntroduction about-ajax-framework
Introduction about-ajax-framework
 
M Ramya
M RamyaM Ramya
M Ramya
 
M6 l8-ajax-handout
M6 l8-ajax-handoutM6 l8-ajax-handout
M6 l8-ajax-handout
 
Ajax tutorial by bally chohan
Ajax tutorial by bally chohanAjax tutorial by bally chohan
Ajax tutorial by bally chohan
 

More from Rajkiran Mummadi

Servlets
ServletsServlets
Php
PhpPhp
Javabeans .pdf
Javabeans .pdfJavabeans .pdf
Javabeans .pdf
Rajkiran Mummadi
 
Java beans
Java beansJava beans
Java beans
Rajkiran Mummadi
 
Java script
Java scriptJava script
Java script
Rajkiran Mummadi
 
Google glasses
Google glassesGoogle glasses
Google glasses
Rajkiran Mummadi
 
Environmental hazards
Environmental hazardsEnvironmental hazards
Environmental hazards
Rajkiran Mummadi
 
Wcharging
WchargingWcharging
Wcharging
Rajkiran Mummadi
 
Wireless charging
Wireless chargingWireless charging
Wireless charging
Rajkiran Mummadi
 
Standard bop
Standard bopStandard bop
Standard bop
Rajkiran Mummadi
 
Russian technology in indian banking system 1
Russian technology in indian banking system 1Russian technology in indian banking system 1
Russian technology in indian banking system 1
Rajkiran Mummadi
 
Ai presentation
Ai presentationAi presentation
Ai presentation
Rajkiran Mummadi
 
Loon
LoonLoon
Triggers
TriggersTriggers
autonomous cars
autonomous carsautonomous cars
autonomous cars
Rajkiran Mummadi
 
ET3
ET3ET3
demonetisation
demonetisationdemonetisation
demonetisation
Rajkiran Mummadi
 

More from Rajkiran Mummadi (17)

Servlets
ServletsServlets
Servlets
 
Php
PhpPhp
Php
 
Javabeans .pdf
Javabeans .pdfJavabeans .pdf
Javabeans .pdf
 
Java beans
Java beansJava beans
Java beans
 
Java script
Java scriptJava script
Java script
 
Google glasses
Google glassesGoogle glasses
Google glasses
 
Environmental hazards
Environmental hazardsEnvironmental hazards
Environmental hazards
 
Wcharging
WchargingWcharging
Wcharging
 
Wireless charging
Wireless chargingWireless charging
Wireless charging
 
Standard bop
Standard bopStandard bop
Standard bop
 
Russian technology in indian banking system 1
Russian technology in indian banking system 1Russian technology in indian banking system 1
Russian technology in indian banking system 1
 
Ai presentation
Ai presentationAi presentation
Ai presentation
 
Loon
LoonLoon
Loon
 
Triggers
TriggersTriggers
Triggers
 
autonomous cars
autonomous carsautonomous cars
autonomous cars
 
ET3
ET3ET3
ET3
 
demonetisation
demonetisationdemonetisation
demonetisation
 

Recently uploaded

FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
Jen Stirrup
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
Vlad Stirbu
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 

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.