SlideShare uma empresa Scribd logo
1 de 25
Baixar para ler offline
Ajax
Relevance of Ajax
• Normally we exchange data with server in any of following scenarios
 We click on a link to request a new page
 We submit a form to send the user data to server
• In both cases the whole webpage reloads
• AJAX is the art of exchanging data with a server, and updating parts of a web
page - without reloading the whole page.
A - Asynchronous
J - JavaScript
A - And
X - XML
“AJAX is not a new programming language, but a new way to use existing standards.”
Browser Web server
Web pages without Ajax
Browser Web server
Web pages with Ajax
How to code ajax?
Ajax is just a JavaScript function which can be called like any other
functions in JavaScript
Step 1 : create XMLHttpRequest : which is a special object to exchange data with
server
Step 2 : send server request using the above XMLHttpRequest send() method
Step 3 : Receive response from server (response can be success or error)
Step 4 : If response is success get the resposeText and display it on the html page
using JavaScript DOM manipulation
Step 5 : if repose is error acknowledge accordingly
Step 1: creating xmlHttpRequest
var xmlhttp;
if (window.XMLHttpRequest)
{ // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
Else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
Step 1: creating xmlHttpRequest
var xmlhttp;
if (window.XMLHttpRequest)
{ // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
Else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
Creating a normal variable
which will be assigned as
an object in coming lines
Step 1: creating xmlHttpRequest
var xmlhttp;
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
Else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
All modern browsers
(IE7+, Firefox, Chrome,
Safari, and Opera) have a
built-in XMLHttpRequest
object.
Old versions of Internet
Explorer (IE5 and IE6) use
an ActiveX Object: for
data exchange
So this code Detects if the
browser has
XMLHTTPRequest
functionality or not
Step 1: creating xmlHttpRequest
var xmlhttp;
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
Else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
If it returns true we make
the the variable xmlhttp
assigned to the
XMLHttpRequest object
Step 1: creating xmlHttpRequest
var xmlhttp;
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
Else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
Else statement evaluates
true if the browser doesnt
support
XMLHttpRequest(means
the browser id old
version)
So in old versions
ActiveXobject serve the
same purpose . So we
assign xmlhttp into
ActiveX object
Step 2: Send a request to server
xmlhttp.open("GET","ajax_info.txt",true);
xmlhttp.send();
As xmlhttp is an object it will
have several methods associated
with him like open(),send() etc
Open() : Specifies the type of
request, the URL, and if the
request should be handled
asynchronously or not.
Type: GET / POST
URL : the path to page from
where we want the data from
TRUE : means data has to be
transmitted asynchronously
Step 2: Send a request to server
xmlhttp.open("GET","ajax_info.txt",true);
xmlhttp.send();
Sends the request off to the
server.
Step 3: Server response
To get the response from a server, use the responseText or responseXML
property of the XMLHttpRequest object.
« responseText : Get the response data as a string
« responseXML : Get the response data as XML
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
We receive the respose from server in a string format
which will be stored in resposeText property of
xmlhttp object
<script>
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","ajax_info.txt",false);
xmlhttp.send();
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
</script>
<body>
<div id="myDiv"><h2>Let AJAX change this text</h2></div>
<button type="button" onclick="loadXMLDoc()">Change Content</button>
</body>
Properties
Onreadystatechange
readyState
Status
responseText
responseXml
Methods
Send()
Open()
setRequestHeader()
XMLHTTP in detail
As you are well aware xmlhtp is just an object,
Which means it will have number of member
functions and properties . We will look detailed
into it
Properties
Onreadystatechange
readyState
Status
responseText
responseXml
Methods
Send()
Open()
setRequestHeader()
xmlhttp
We’ve already discussed about this
properties and methods
XMLHTTP in detail
Properties
Onreadystatechange
readyState
Status
responseText
responseXml
Methods
Send()
Open()
setRequestHeader()
xmlhttp
Stores a function (or the name of a
function) to be called automatically
each time the readyState property
changes
XMLHTTP in detail
Properties
Onreadystatechange
readyState
Status
responseText
responseXml
Methods
Send()
Open()
setRequestHeader()
xmlhttp
Holds the status of the
XMLHttpRequest.
Changes from 0 to 4:
0: request not initialized
1: server connection established
2: request received
3: processing request
4: request finished and response is
ready
XMLHTTP in detail
Properties
Onreadystatechange
readyState
Status
responseText
responseXml
Methods
Send()
Open()
setRequestHeader()
xmlhttp
200: "OK"
404: Page not found
XMLHTTP in detail
Properties
Onreadystatechange
readyState
Status
responseText
responseXml
Methods
Send()
Open()
setRequestHeader()
xmlhttp
Adds HTTP headers to the request.
This method takes 2 parameters
header: specifies the header name
value: specifies the header value
Eg:
xmlhttp.setRequestHeader("Content-
type","application/x-www-form-
urlencoded");
XMLHTTP in detail
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","ajax_info.txt",true);
xmlhttp.send();
}
End of day
If this presentation helped you, please visit our
page facebook.com/baabtra and like it.
Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com
Contact Us
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com

Mais conteúdo relacionado

Mais procurados

Ajax Fundamentals Web Applications
Ajax Fundamentals Web ApplicationsAjax Fundamentals Web Applications
Ajax Fundamentals Web Applications
dominion
 
Ajax Presentation
Ajax PresentationAjax Presentation
Ajax Presentation
ronaldmam
 
Java Script - A New Look
Java Script - A New LookJava Script - A New Look
Java Script - A New Look
rumsan
 

Mais procurados (20)

Lec 7
Lec 7Lec 7
Lec 7
 
Ajax Fundamentals Web Applications
Ajax Fundamentals Web ApplicationsAjax Fundamentals Web Applications
Ajax Fundamentals Web Applications
 
Javascript in C# for Lightweight Applications
Javascript in C# for Lightweight ApplicationsJavascript in C# for Lightweight Applications
Javascript in C# for Lightweight Applications
 
Copy of ajax tutorial
Copy of ajax tutorialCopy of ajax tutorial
Copy of ajax tutorial
 
Pracitcal AJAX
Pracitcal AJAXPracitcal AJAX
Pracitcal AJAX
 
Ajax
AjaxAjax
Ajax
 
ajax_pdf
ajax_pdfajax_pdf
ajax_pdf
 
Ajax Presentation
Ajax PresentationAjax Presentation
Ajax Presentation
 
Beyond HTML: Tools for Building Web 2.0 Apps
Beyond HTML: Tools for Building Web 2.0 AppsBeyond HTML: Tools for Building Web 2.0 Apps
Beyond HTML: Tools for Building Web 2.0 Apps
 
Ajax
AjaxAjax
Ajax
 
Ajax
AjaxAjax
Ajax
 
Java Script - A New Look
Java Script - A New LookJava Script - A New Look
Java Script - A New Look
 
2310 b 11
2310 b 112310 b 11
2310 b 11
 
AJAX
AJAXAJAX
AJAX
 
Pascarello_Investigating JavaScript and Ajax Security
Pascarello_Investigating JavaScript and Ajax SecurityPascarello_Investigating JavaScript and Ajax Security
Pascarello_Investigating JavaScript and Ajax Security
 
Introduction to Ajax programming
Introduction to Ajax programmingIntroduction to Ajax programming
Introduction to Ajax programming
 
Asp db
Asp dbAsp db
Asp db
 
XAML Data Binding in UWP
XAML Data Binding in UWPXAML Data Binding in UWP
XAML Data Binding in UWP
 
AJAX Crawl
AJAX CrawlAJAX Crawl
AJAX Crawl
 
Ajax
AjaxAjax
Ajax
 

Destaque (7)

Introduction to c part -1
Introduction to c   part -1Introduction to c   part -1
Introduction to c part -1
 
Xml passing in java
Xml passing in javaXml passing in java
Xml passing in java
 
Threads in python
Threads in pythonThreads in python
Threads in python
 
Jquery library
Jquery libraryJquery library
Jquery library
 
Ajax
AjaxAjax
Ajax
 
File oparation in c
File oparation in cFile oparation in c
File oparation in c
 
Database design
Database designDatabase design
Database design
 

Semelhante a Ajax

Semelhante a Ajax (20)

Ajax
AjaxAjax
Ajax
 
Core Java tutorial at Unit Nexus
Core Java tutorial at Unit NexusCore Java tutorial at Unit Nexus
Core Java tutorial at Unit Nexus
 
Xml http request
Xml http requestXml http request
Xml http request
 
AJAX.pptx
AJAX.pptxAJAX.pptx
AJAX.pptx
 
Ajax
AjaxAjax
Ajax
 
Ajax
AjaxAjax
Ajax
 
Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)
 
Ajax and xml
Ajax and xmlAjax and xml
Ajax and xml
 
Ajax Tuturial
Ajax TuturialAjax Tuturial
Ajax Tuturial
 
Ajax.ppt
Ajax.pptAjax.ppt
Ajax.ppt
 
Ajax Ppt
Ajax PptAjax Ppt
Ajax Ppt
 
mukesh
mukeshmukesh
mukesh
 
Unit-5.pptx
Unit-5.pptxUnit-5.pptx
Unit-5.pptx
 
Ajax tutorial by bally chohan
Ajax tutorial by bally chohanAjax tutorial by bally chohan
Ajax tutorial by bally chohan
 
PHP - Introduction to PHP AJAX
PHP -  Introduction to PHP AJAXPHP -  Introduction to PHP AJAX
PHP - Introduction to PHP AJAX
 
Ajax
AjaxAjax
Ajax
 
Building Applications Using Ajax
Building Applications Using AjaxBuilding Applications Using Ajax
Building Applications Using Ajax
 
Ajax
AjaxAjax
Ajax
 
SynapseIndia dotnet development ajax client library
SynapseIndia dotnet development ajax client librarySynapseIndia dotnet development ajax client library
SynapseIndia dotnet development ajax client library
 
AJAX
AJAXAJAX
AJAX
 

Mais de baabtra.com - No. 1 supplier of quality freshers

Mais de baabtra.com - No. 1 supplier of quality freshers (20)

Agile methodology and scrum development
Agile methodology and scrum developmentAgile methodology and scrum development
Agile methodology and scrum development
 
Best coding practices
Best coding practicesBest coding practices
Best coding practices
 
Core java - baabtra
Core java - baabtraCore java - baabtra
Core java - baabtra
 
Acquiring new skills what you should know
Acquiring new skills   what you should knowAcquiring new skills   what you should know
Acquiring new skills what you should know
 
Baabtra.com programming at school
Baabtra.com programming at schoolBaabtra.com programming at school
Baabtra.com programming at school
 
99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love 99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
 
Chapter 5 transactions and dcl statements
Chapter 5  transactions and dcl statementsChapter 5  transactions and dcl statements
Chapter 5 transactions and dcl statements
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Microsoft holo lens
Microsoft holo lensMicrosoft holo lens
Microsoft holo lens
 
Blue brain
Blue brainBlue brain
Blue brain
 
5g
5g5g
5g
 
Aptitude skills baabtra
Aptitude skills baabtraAptitude skills baabtra
Aptitude skills baabtra
 
Gd baabtra
Gd baabtraGd baabtra
Gd baabtra
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 

Ajax

  • 2. Relevance of Ajax • Normally we exchange data with server in any of following scenarios  We click on a link to request a new page  We submit a form to send the user data to server • In both cases the whole webpage reloads • AJAX is the art of exchanging data with a server, and updating parts of a web page - without reloading the whole page.
  • 3. A - Asynchronous J - JavaScript A - And X - XML “AJAX is not a new programming language, but a new way to use existing standards.”
  • 4. Browser Web server Web pages without Ajax
  • 5. Browser Web server Web pages with Ajax
  • 6. How to code ajax? Ajax is just a JavaScript function which can be called like any other functions in JavaScript Step 1 : create XMLHttpRequest : which is a special object to exchange data with server Step 2 : send server request using the above XMLHttpRequest send() method Step 3 : Receive response from server (response can be success or error) Step 4 : If response is success get the resposeText and display it on the html page using JavaScript DOM manipulation Step 5 : if repose is error acknowledge accordingly
  • 7. Step 1: creating xmlHttpRequest var xmlhttp; if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } Else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
  • 8. Step 1: creating xmlHttpRequest var xmlhttp; if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } Else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } Creating a normal variable which will be assigned as an object in coming lines
  • 9. Step 1: creating xmlHttpRequest var xmlhttp; if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } Else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } All modern browsers (IE7+, Firefox, Chrome, Safari, and Opera) have a built-in XMLHttpRequest object. Old versions of Internet Explorer (IE5 and IE6) use an ActiveX Object: for data exchange So this code Detects if the browser has XMLHTTPRequest functionality or not
  • 10. Step 1: creating xmlHttpRequest var xmlhttp; if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } Else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } If it returns true we make the the variable xmlhttp assigned to the XMLHttpRequest object
  • 11. Step 1: creating xmlHttpRequest var xmlhttp; if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } Else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } Else statement evaluates true if the browser doesnt support XMLHttpRequest(means the browser id old version) So in old versions ActiveXobject serve the same purpose . So we assign xmlhttp into ActiveX object
  • 12. Step 2: Send a request to server xmlhttp.open("GET","ajax_info.txt",true); xmlhttp.send(); As xmlhttp is an object it will have several methods associated with him like open(),send() etc Open() : Specifies the type of request, the URL, and if the request should be handled asynchronously or not. Type: GET / POST URL : the path to page from where we want the data from TRUE : means data has to be transmitted asynchronously
  • 13. Step 2: Send a request to server xmlhttp.open("GET","ajax_info.txt",true); xmlhttp.send(); Sends the request off to the server.
  • 14. Step 3: Server response To get the response from a server, use the responseText or responseXML property of the XMLHttpRequest object. « responseText : Get the response data as a string « responseXML : Get the response data as XML document.getElementById("myDiv").innerHTML=xmlhttp.responseText; We receive the respose from server in a string format which will be stored in resposeText property of xmlhttp object
  • 15. <script> function loadXMLDoc() { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("GET","ajax_info.txt",false); xmlhttp.send(); document.getElementById("myDiv").innerHTML=xmlhttp.responseText; } </script> <body> <div id="myDiv"><h2>Let AJAX change this text</h2></div> <button type="button" onclick="loadXMLDoc()">Change Content</button> </body>
  • 16. Properties Onreadystatechange readyState Status responseText responseXml Methods Send() Open() setRequestHeader() XMLHTTP in detail As you are well aware xmlhtp is just an object, Which means it will have number of member functions and properties . We will look detailed into it
  • 18. Properties Onreadystatechange readyState Status responseText responseXml Methods Send() Open() setRequestHeader() xmlhttp Stores a function (or the name of a function) to be called automatically each time the readyState property changes XMLHTTP in detail
  • 19. Properties Onreadystatechange readyState Status responseText responseXml Methods Send() Open() setRequestHeader() xmlhttp Holds the status of the XMLHttpRequest. Changes from 0 to 4: 0: request not initialized 1: server connection established 2: request received 3: processing request 4: request finished and response is ready XMLHTTP in detail
  • 21. Properties Onreadystatechange readyState Status responseText responseXml Methods Send() Open() setRequestHeader() xmlhttp Adds HTTP headers to the request. This method takes 2 parameters header: specifies the header name value: specifies the header value Eg: xmlhttp.setRequestHeader("Content- type","application/x-www-form- urlencoded"); XMLHTTP in detail
  • 22. function loadXMLDoc() { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("myDiv").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","ajax_info.txt",true); xmlhttp.send(); }
  • 24. If this presentation helped you, please visit our page facebook.com/baabtra and like it. Thanks in advance. www.baabtra.com | www.massbaab.com |www.baabte.com
  • 25. Contact Us Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com