SlideShare a Scribd company logo
A New Way To WebA New Way To Web
Applications DevelopmentApplications Development
AJAXAJAX
Mrs.C.SanthiyaMrs.C.Santhiya
Assistant ProfessorAssistant Professor
TCE,MaduraiTCE,Madurai
RIA ExRIA Ex
Rich Internet Application (RIA) likesRich Internet Application (RIA) likes
following ?following ?
Client-Side ProgrammingClient-Side Programming
Recall the technologies comprisingRecall the technologies comprising DHTMLDHTML
1.1. HTML (HTML (contentcontent))
2.2. Document Object Model (DOM) (Document Object Model (DOM) (data structuredata structure))
3.3. JavaScript (JavaScript (behaviourbehaviour))
4.4. Cascading Style Sheets (Cascading Style Sheets (presentationpresentation))

JavaScriptJavaScript is a powerful tool for dynamic client-side programmingis a powerful tool for dynamic client-side programming
How does AJAX work?How does AJAX work?
• AJAXAJAX uses a programming model withuses a programming model with displaydisplay andand eventsevents..
• These events areThese events are user actionsuser actions, they call, they call functionsfunctions associatedassociated
withwith elements of the web pageelements of the web page..
• InteractivityInteractivity is achieved withis achieved with formsforms andand buttonsbuttons..
• DOMDOM allows to link elements of the page withallows to link elements of the page with actionsactions and also toand also to
extract data fromextract data from XMLXML or Text files provided by the server.or Text files provided by the server.
Classic Web Application ModelClassic Web Application Model
Classic Web Application ModelClassic Web Application Model
Do not work well for some webDo not work well for some web
applications.applications.
Real time validation.Real time validation.
Loss of operation context during pageLoss of operation context during page
refresh.refresh.
Excessive server load and bandwidthExcessive server load and bandwidth
consumption due to redundant pageconsumption due to redundant page
refreshes.refreshes.
What isWhat is AJAXAJAX??
AAsynchronoussynchronous JJavaScriptavaScript AAndnd XXMLML
AJAXAJAX is not a technology itself.is not a technology itself.
Refers to the use of a group of technologiesRefers to the use of a group of technologies
together.together.
– HTMLHTML oror DHTMLDHTML andand CSSCSS for presentationfor presentation
information.information.
– Document Object ModelDocument Object Model manipulated throughmanipulated through
JavaScriptJavaScript to dynamically display and interact with theto dynamically display and interact with the
information presented.information presented.
– XMLHttpRequestXMLHttpRequest object to exchange dataobject to exchange data
asynchronously with the web server.asynchronously with the web server.
What are the Issues with AJAX?What are the Issues with AJAX?
User does not know updates will occur.User does not know updates will occur.
User does not notice an update.User does not notice an update.
User can not find the updated information.User can not find the updated information.
Unexpected changes in focus.Unexpected changes in focus.
Loss of Back button functionality*.Loss of Back button functionality*.
URIs can not be bookmarked*.URIs can not be bookmarked*.
AJAXAJAX Application ModelApplication Model
Classic VsClassic Vs AJAXAJAX
Creating the ObjectCreating the Object
For Safari and MozillaFor Safari and Mozilla
var req = new XMLHttpRequest();var req = new XMLHttpRequest();
For the ActiveX branchFor the ActiveX branch
var req = newvar req = new
ActiveXObject("Microsoft.XMLHTTP");ActiveXObject("Microsoft.XMLHTTP");
The XMLHttpRequest object (cont.)The XMLHttpRequest object (cont.)
function getXMLHttpRequest()function getXMLHttpRequest()
/* This function attempts to get an Ajax request object by trying/* This function attempts to get an Ajax request object by trying
a few different methods for different browsers. */a few different methods for different browsers. */
{{
var request, err;var request, err;
try {try {
request = new XMLHttpRequest(); // Firefox, Safari, Opera, etc.request = new XMLHttpRequest(); // Firefox, Safari, Opera, etc.
}}
catch(err) {catch(err) {
try { // first attempt for Internet Explorertry { // first attempt for Internet Explorer
request = new ActiveXObject("MSXML2.XMLHttp.6.0");request = new ActiveXObject("MSXML2.XMLHttp.6.0");
}}
catch (err) {catch (err) {
try { // second attempt for Internet Explorertry { // second attempt for Internet Explorer
request = new ActiveXObject("MSXML2.XMLHttp.3.0");request = new ActiveXObject("MSXML2.XMLHttp.3.0");
}}
catch (err) {catch (err) {
request = false; // oops, can’t create one!request = false; // oops, can’t create one!
}}
}}
}}
return request;return request;
}}
If this function doesn’t return “false” then we were successful in creating anIf this function doesn’t return “false” then we were successful in creating an XMLHttpRequestXMLHttpRequest object.object.
Object MethodsObject Methods
MethodMethod DescriptionDescription
abort()abort() Stops the current request.Stops the current request.
getAllResponseHeaders()getAllResponseHeaders() Returns complete set of headersReturns complete set of headers
(labels and values) as a string(labels and values) as a string
getResponseHeader("getResponseHeader("headerLabelheaderLabel")") Assigns destination URL, method, andAssigns destination URL, method, and
other optional attributes of a pendingother optional attributes of a pending
requestrequest
open("open("methodmethod", "", "URLURL"[,"[, asyncFlagasyncFlag[,[,
""userNameuserName"[, ""[, "passwordpassword"]]])"]]])
Assigns destination URL, method, andAssigns destination URL, method, and
other optional attributes of a pendingother optional attributes of a pending
requestrequest
send(send(contentcontent)) Transmits the request, optionally withTransmits the request, optionally with
postable string or DOM object datapostable string or DOM object data
setRequestHeader("setRequestHeader("labellabel", "", "valuevalue")") Assigns a label/value pair to theAssigns a label/value pair to the
header to be sent with a requestheader to be sent with a request
Object PropertiesObject Properties
PropertyProperty DescriptionDescription
onreadystatechangeonreadystatechange Event handler for an event that fires atEvent handler for an event that fires at
every state changeevery state change
readyStatereadyState Object status integer:Object status integer:
0 = uninitialized0 = uninitialized
1 = loading1 = loading
2 = loaded2 = loaded
3 = interactive3 = interactive
4 = complete4 = complete
responseTextresponseText String version of data returned from serverString version of data returned from server
processprocess
responseXMLresponseXML DOM-compatible document object of dataDOM-compatible document object of data
returned from server processreturned from server process
statusstatus Numeric code returned by server, such asNumeric code returned by server, such as
404 for "Not Found" or 200 for "OK"404 for "Not Found" or 200 for "OK"
statusTextstatusText String message accompanying the statusString message accompanying the status
codecode
A general skeleton for an Ajax applicationA general skeleton for an Ajax application
<script type="text/javascript">
// ***** include the getXMLHttpRequest function defined before
var ajaxRequest = getXMLHttpRequest();
if (ajaxRequest) { // if the object was created successfully
ajaxRequest.onreadystatechange = ajaxResponse;
ajaxRequest.open("GET", "search.php?query=Bob");
ajaxRequest.send(null);
}
function ajaxResponse() //This gets called when the readyState changes.
{
if (ajaxRequest.readyState != 4) // check to see if we’re done
{ return; }
else {
if (ajaxRequest.status == 200) // check to see if successful
{ // process server data here. . . }
else {
alert("Request failed: " + ajaxRequest.statusText);
}
}
}
</script>
Database Stock ExampleDatabase Stock Example
AJAXAJAX can be used to runrun PHP scripts that obtain
up-to-the-minute information stored on a database.
AJAXAJAX can be used to runrun PHP scripts that obtain
up-to-the-minute information stored on a database.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xml:lang="en">
<head>
<title>Stock Script</title>
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1" />
<script type="text/javascript"
src="getxmlhttprequest.js">
</script>
<script type="text/javascript" src="example18-2.js">
</script>
</head>
...
body>
<h2>Fruit Stock Information:</h2>
<form action="" method="post">
<p>
<label for="strStock">Stock Query: </label>
<input type="text" name="strStock" id="strStock"/>
</p>
<p>
<input type="button" value="Check" onclick="startJS();"/>
</p>
<div id="strStockResult"></div>
</form>
</body>
</html>
AJAX –AJAX – connectconnect to server,to server, sendsend requestrequest
function startJS() {
xhrequest = null;
try {
xhrequest = getXMLHttpRequest();
}
catch(error) {
document.write("Cannot run Ajax code using this browser");
}
if(xhrequest != null) { JavaScript gets a reference to any element in a
page using DOM API
// get form values ID Attribute
var strStock = document.getElementById("strStock").value;
var strUrl = "example18-2.php??strStock=" + strStock;
xhrequest.onreadystatechange = changePagechangePage; Php script +query
xhrequest.open("GETGET", strUrl, true);
xhrequest.send(null);
}
}
function changePage() {
if (xhrequest.readyState == 44 && xhrequest.status == 200200) {
var strResponsestrResponse = xhrequest.responseText;
document.getElementById("strStockResult").innerHTML =
strResponsestrResponse;
}
}
function getXMLHttpRequest() {
var xhrequest = null;
open window in browser
if(window.XMLHttpRequestXMLHttpRequest) {
property s present
// If IE7, Mozilla, Safari, etc: Use native object
try {
xhrequest = new XMLHttpRequest();
return xhrequest;
use native scripting
}
catch(exception) {ss
// OK, just carry on looking
}
}
Steps of AjaxSteps of Ajax
A client event occurs.
An XMLHttpRequest object is created.
The XMLHttpRequest object is configured.
The XMLHttpRequest object makes an
asynchronous request to the Webserver.
The Webserver returns the result containing XML
document.
The XMLHttpRequest object calls the callback()
function and processes the result.
The HTML DOM is updated.
Ad

More Related Content

What's hot (20)

Ajax ppt - 32 slides
Ajax ppt - 32 slidesAjax ppt - 32 slides
Ajax ppt - 32 slides
Smithss25
 
Chap 4 PHP.pdf
Chap 4 PHP.pdfChap 4 PHP.pdf
Chap 4 PHP.pdf
HASENSEID
 
Training & Placement Database Management System
Training & Placement Database Management SystemTraining & Placement Database Management System
Training & Placement Database Management System
Rohit Mate
 
HTTP Request and Response Structure
HTTP Request and Response StructureHTTP Request and Response Structure
HTTP Request and Response Structure
BhagyashreeGajera1
 
Php forms
Php formsPhp forms
Php forms
Anne Lee
 
Css
CssCss
Css
Manav Prasad
 
Php session
Php sessionPhp session
Php session
argusacademy
 
Student Result
Student ResultStudent Result
Student Result
Md. Riadul Islam
 
Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1
Gheyath M. Othman
 
PHP - Introduction to PHP AJAX
PHP -  Introduction to PHP AJAXPHP -  Introduction to PHP AJAX
PHP - Introduction to PHP AJAX
Vibrant Technologies & Computers
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events
WebStackAcademy
 
02 xml schema
02 xml schema02 xml schema
02 xml schema
Baskarkncet
 
Ajax.ppt
Ajax.pptAjax.ppt
Ajax.ppt
MAGNA COLLEGE OF ENGINEERING
 
UNIVERSITY MANAGEMENT SYSTEM.pptx
UNIVERSITY MANAGEMENT SYSTEM.pptxUNIVERSITY MANAGEMENT SYSTEM.pptx
UNIVERSITY MANAGEMENT SYSTEM.pptx
shivantGupta1
 
Presentation of database management system
Presentation of database management systemPresentation of database management system
Presentation of database management system
Md. Touhidur Rahman
 
Loops in java script
Loops in java scriptLoops in java script
Loops in java script
Ravi Bhadauria
 
Oops concepts in php
Oops concepts in phpOops concepts in php
Oops concepts in php
CPD INDIA
 
Php Tutorials for Beginners
Php Tutorials for BeginnersPhp Tutorials for Beginners
Php Tutorials for Beginners
Vineet Kumar Saini
 
JavaScript guide 2020 Learn JavaScript
JavaScript guide 2020 Learn JavaScriptJavaScript guide 2020 Learn JavaScript
JavaScript guide 2020 Learn JavaScript
Laurence Svekis ✔
 
PHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and requirePHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and require
TheCreativedev Blog
 
Ajax ppt - 32 slides
Ajax ppt - 32 slidesAjax ppt - 32 slides
Ajax ppt - 32 slides
Smithss25
 
Chap 4 PHP.pdf
Chap 4 PHP.pdfChap 4 PHP.pdf
Chap 4 PHP.pdf
HASENSEID
 
Training & Placement Database Management System
Training & Placement Database Management SystemTraining & Placement Database Management System
Training & Placement Database Management System
Rohit Mate
 
HTTP Request and Response Structure
HTTP Request and Response StructureHTTP Request and Response Structure
HTTP Request and Response Structure
BhagyashreeGajera1
 
Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1
Gheyath M. Othman
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events
WebStackAcademy
 
UNIVERSITY MANAGEMENT SYSTEM.pptx
UNIVERSITY MANAGEMENT SYSTEM.pptxUNIVERSITY MANAGEMENT SYSTEM.pptx
UNIVERSITY MANAGEMENT SYSTEM.pptx
shivantGupta1
 
Presentation of database management system
Presentation of database management systemPresentation of database management system
Presentation of database management system
Md. Touhidur Rahman
 
Oops concepts in php
Oops concepts in phpOops concepts in php
Oops concepts in php
CPD INDIA
 
JavaScript guide 2020 Learn JavaScript
JavaScript guide 2020 Learn JavaScriptJavaScript guide 2020 Learn JavaScript
JavaScript guide 2020 Learn JavaScript
Laurence Svekis ✔
 
PHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and requirePHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and require
TheCreativedev Blog
 

Similar to Ajax Lecture Notes (20)

Ajax
AjaxAjax
Ajax
husnara mohammad
 
Ajax
AjaxAjax
Ajax
rahmed_sct
 
Ajax Introduction
Ajax IntroductionAjax Introduction
Ajax Introduction
Oliver Cai
 
Ajax
AjaxAjax
Ajax
Bharath Palaksha
 
Ajax tutorial
Ajax tutorialAjax tutorial
Ajax tutorial
Kat Roque
 
SynapseIndia dotnet development ajax client library
SynapseIndia dotnet development ajax client librarySynapseIndia dotnet development ajax client library
SynapseIndia dotnet development ajax client library
Synapseindiappsdevelopment
 
Building Applications Using Ajax
Building Applications Using AjaxBuilding Applications Using Ajax
Building Applications Using Ajax
s_pradeep
 
Ajax tutorial by bally chohan
Ajax tutorial by bally chohanAjax tutorial by bally chohan
Ajax tutorial by bally chohan
WebVineet
 
Ajax
AjaxAjax
Ajax
NIRMAL FELIX
 
Ajax
AjaxAjax
Ajax
Dumindu Pahalawatta
 
Pascarello_Investigating JavaScript and Ajax Security
Pascarello_Investigating JavaScript and Ajax SecurityPascarello_Investigating JavaScript and Ajax Security
Pascarello_Investigating JavaScript and Ajax Security
amiable_indian
 
Ajax
AjaxAjax
Ajax
Manav Prasad
 
Web Programming using Asynchronous JavaX
Web Programming using Asynchronous JavaXWeb Programming using Asynchronous JavaX
Web Programming using Asynchronous JavaX
SivanN6
 
Web-Engineering-Lec-14 (1) .pptx
Web-Engineering-Lec-14 (1)                    .pptxWeb-Engineering-Lec-14 (1)                    .pptx
Web-Engineering-Lec-14 (1) .pptx
iamayesha2526
 
Web-Engineering-Lec-14 (1 ).pptx
Web-Engineering-Lec-14 (1           ).pptxWeb-Engineering-Lec-14 (1           ).pptx
Web-Engineering-Lec-14 (1 ).pptx
iamayesha2526
 
Ajax
AjaxAjax
Ajax
Yoga Raja
 
AJAX
AJAXAJAX
AJAX
Gouthaman V
 
AJAX
AJAXAJAX
AJAX
Gouthaman V
 
AJAX
AJAXAJAX
AJAX
ankurgupta
 
Copy of ajax tutorial
Copy of ajax tutorialCopy of ajax tutorial
Copy of ajax tutorial
Abhishek Kesharwani
 
Ad

More from Santhiya Grace (10)

Xml p5 Lecture Notes
Xml p5 Lecture NotesXml p5 Lecture Notes
Xml p5 Lecture Notes
Santhiya Grace
 
Xml p4 Lecture Notes
Xml p4  Lecture NotesXml p4  Lecture Notes
Xml p4 Lecture Notes
Santhiya Grace
 
Xml p3 -Lecture Notes
Xml p3 -Lecture NotesXml p3 -Lecture Notes
Xml p3 -Lecture Notes
Santhiya Grace
 
Xml p2 Lecture Notes
Xml p2 Lecture NotesXml p2 Lecture Notes
Xml p2 Lecture Notes
Santhiya Grace
 
Xml Lecture Notes
Xml Lecture NotesXml Lecture Notes
Xml Lecture Notes
Santhiya Grace
 
Php Lecture Notes
Php Lecture NotesPhp Lecture Notes
Php Lecture Notes
Santhiya Grace
 
Events Lecture Notes
Events Lecture NotesEvents Lecture Notes
Events Lecture Notes
Santhiya Grace
 
Css lecture notes
Css lecture notesCss lecture notes
Css lecture notes
Santhiya Grace
 
Software Quality Assurance
Software Quality AssuranceSoftware Quality Assurance
Software Quality Assurance
Santhiya Grace
 
Software Quality Assurance class 1
Software Quality Assurance  class 1Software Quality Assurance  class 1
Software Quality Assurance class 1
Santhiya Grace
 
Ad

Recently uploaded (20)

new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
Smart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineeringSmart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineering
rushikeshnavghare94
 
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E..."Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
Infopitaara
 
railway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forgingrailway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forging
Javad Kadkhodapour
 
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITYADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ijscai
 
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptxLidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
RishavKumar530754
 
introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design ThinkingDT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DhruvChotaliya2
 
DSP and MV the Color image processing.ppt
DSP and MV the  Color image processing.pptDSP and MV the  Color image processing.ppt
DSP and MV the Color image processing.ppt
HafizAhamed8
 
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdfMAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
ssuser562df4
 
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Journal of Soft Computing in Civil Engineering
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
Data Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptxData Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
Avnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights FlyerAvnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights Flyer
WillDavies22
 
International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)
samueljackson3773
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
Artificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptxArtificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptx
aditichinar
 
Reagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptxReagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptx
AlejandroOdio
 
theory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptxtheory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptx
sanchezvanessa7896
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
Smart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineeringSmart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineering
rushikeshnavghare94
 
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E..."Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
Infopitaara
 
railway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forgingrailway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forging
Javad Kadkhodapour
 
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITYADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ijscai
 
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptxLidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
RishavKumar530754
 
introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design ThinkingDT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DhruvChotaliya2
 
DSP and MV the Color image processing.ppt
DSP and MV the  Color image processing.pptDSP and MV the  Color image processing.ppt
DSP and MV the Color image processing.ppt
HafizAhamed8
 
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdfMAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
ssuser562df4
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
Data Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptxData Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
Avnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights FlyerAvnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights Flyer
WillDavies22
 
International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)
samueljackson3773
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
Artificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptxArtificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptx
aditichinar
 
Reagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptxReagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptx
AlejandroOdio
 
theory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptxtheory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptx
sanchezvanessa7896
 

Ajax Lecture Notes

  • 1. A New Way To WebA New Way To Web Applications DevelopmentApplications Development AJAXAJAX Mrs.C.SanthiyaMrs.C.Santhiya Assistant ProfessorAssistant Professor TCE,MaduraiTCE,Madurai
  • 2. RIA ExRIA Ex Rich Internet Application (RIA) likesRich Internet Application (RIA) likes following ?following ?
  • 3. Client-Side ProgrammingClient-Side Programming Recall the technologies comprisingRecall the technologies comprising DHTMLDHTML 1.1. HTML (HTML (contentcontent)) 2.2. Document Object Model (DOM) (Document Object Model (DOM) (data structuredata structure)) 3.3. JavaScript (JavaScript (behaviourbehaviour)) 4.4. Cascading Style Sheets (Cascading Style Sheets (presentationpresentation))  JavaScriptJavaScript is a powerful tool for dynamic client-side programmingis a powerful tool for dynamic client-side programming
  • 4. How does AJAX work?How does AJAX work? • AJAXAJAX uses a programming model withuses a programming model with displaydisplay andand eventsevents.. • These events areThese events are user actionsuser actions, they call, they call functionsfunctions associatedassociated withwith elements of the web pageelements of the web page.. • InteractivityInteractivity is achieved withis achieved with formsforms andand buttonsbuttons.. • DOMDOM allows to link elements of the page withallows to link elements of the page with actionsactions and also toand also to extract data fromextract data from XMLXML or Text files provided by the server.or Text files provided by the server.
  • 5. Classic Web Application ModelClassic Web Application Model
  • 6. Classic Web Application ModelClassic Web Application Model Do not work well for some webDo not work well for some web applications.applications. Real time validation.Real time validation. Loss of operation context during pageLoss of operation context during page refresh.refresh. Excessive server load and bandwidthExcessive server load and bandwidth consumption due to redundant pageconsumption due to redundant page refreshes.refreshes.
  • 7. What isWhat is AJAXAJAX?? AAsynchronoussynchronous JJavaScriptavaScript AAndnd XXMLML AJAXAJAX is not a technology itself.is not a technology itself. Refers to the use of a group of technologiesRefers to the use of a group of technologies together.together. – HTMLHTML oror DHTMLDHTML andand CSSCSS for presentationfor presentation information.information. – Document Object ModelDocument Object Model manipulated throughmanipulated through JavaScriptJavaScript to dynamically display and interact with theto dynamically display and interact with the information presented.information presented. – XMLHttpRequestXMLHttpRequest object to exchange dataobject to exchange data asynchronously with the web server.asynchronously with the web server.
  • 8. What are the Issues with AJAX?What are the Issues with AJAX? User does not know updates will occur.User does not know updates will occur. User does not notice an update.User does not notice an update. User can not find the updated information.User can not find the updated information. Unexpected changes in focus.Unexpected changes in focus. Loss of Back button functionality*.Loss of Back button functionality*. URIs can not be bookmarked*.URIs can not be bookmarked*.
  • 11. Creating the ObjectCreating the Object For Safari and MozillaFor Safari and Mozilla var req = new XMLHttpRequest();var req = new XMLHttpRequest(); For the ActiveX branchFor the ActiveX branch var req = newvar req = new ActiveXObject("Microsoft.XMLHTTP");ActiveXObject("Microsoft.XMLHTTP");
  • 12. The XMLHttpRequest object (cont.)The XMLHttpRequest object (cont.) function getXMLHttpRequest()function getXMLHttpRequest() /* This function attempts to get an Ajax request object by trying/* This function attempts to get an Ajax request object by trying a few different methods for different browsers. */a few different methods for different browsers. */ {{ var request, err;var request, err; try {try { request = new XMLHttpRequest(); // Firefox, Safari, Opera, etc.request = new XMLHttpRequest(); // Firefox, Safari, Opera, etc. }} catch(err) {catch(err) { try { // first attempt for Internet Explorertry { // first attempt for Internet Explorer request = new ActiveXObject("MSXML2.XMLHttp.6.0");request = new ActiveXObject("MSXML2.XMLHttp.6.0"); }} catch (err) {catch (err) { try { // second attempt for Internet Explorertry { // second attempt for Internet Explorer request = new ActiveXObject("MSXML2.XMLHttp.3.0");request = new ActiveXObject("MSXML2.XMLHttp.3.0"); }} catch (err) {catch (err) { request = false; // oops, can’t create one!request = false; // oops, can’t create one! }} }} }} return request;return request; }} If this function doesn’t return “false” then we were successful in creating anIf this function doesn’t return “false” then we were successful in creating an XMLHttpRequestXMLHttpRequest object.object.
  • 13. Object MethodsObject Methods MethodMethod DescriptionDescription abort()abort() Stops the current request.Stops the current request. getAllResponseHeaders()getAllResponseHeaders() Returns complete set of headersReturns complete set of headers (labels and values) as a string(labels and values) as a string getResponseHeader("getResponseHeader("headerLabelheaderLabel")") Assigns destination URL, method, andAssigns destination URL, method, and other optional attributes of a pendingother optional attributes of a pending requestrequest open("open("methodmethod", "", "URLURL"[,"[, asyncFlagasyncFlag[,[, ""userNameuserName"[, ""[, "passwordpassword"]]])"]]]) Assigns destination URL, method, andAssigns destination URL, method, and other optional attributes of a pendingother optional attributes of a pending requestrequest send(send(contentcontent)) Transmits the request, optionally withTransmits the request, optionally with postable string or DOM object datapostable string or DOM object data setRequestHeader("setRequestHeader("labellabel", "", "valuevalue")") Assigns a label/value pair to theAssigns a label/value pair to the header to be sent with a requestheader to be sent with a request
  • 14. Object PropertiesObject Properties PropertyProperty DescriptionDescription onreadystatechangeonreadystatechange Event handler for an event that fires atEvent handler for an event that fires at every state changeevery state change readyStatereadyState Object status integer:Object status integer: 0 = uninitialized0 = uninitialized 1 = loading1 = loading 2 = loaded2 = loaded 3 = interactive3 = interactive 4 = complete4 = complete responseTextresponseText String version of data returned from serverString version of data returned from server processprocess responseXMLresponseXML DOM-compatible document object of dataDOM-compatible document object of data returned from server processreturned from server process statusstatus Numeric code returned by server, such asNumeric code returned by server, such as 404 for "Not Found" or 200 for "OK"404 for "Not Found" or 200 for "OK" statusTextstatusText String message accompanying the statusString message accompanying the status codecode
  • 15. A general skeleton for an Ajax applicationA general skeleton for an Ajax application <script type="text/javascript"> // ***** include the getXMLHttpRequest function defined before var ajaxRequest = getXMLHttpRequest(); if (ajaxRequest) { // if the object was created successfully ajaxRequest.onreadystatechange = ajaxResponse; ajaxRequest.open("GET", "search.php?query=Bob"); ajaxRequest.send(null); } function ajaxResponse() //This gets called when the readyState changes. { if (ajaxRequest.readyState != 4) // check to see if we’re done { return; } else { if (ajaxRequest.status == 200) // check to see if successful { // process server data here. . . } else { alert("Request failed: " + ajaxRequest.statusText); } } } </script>
  • 16. Database Stock ExampleDatabase Stock Example AJAXAJAX can be used to runrun PHP scripts that obtain up-to-the-minute information stored on a database. AJAXAJAX can be used to runrun PHP scripts that obtain up-to-the-minute information stored on a database.
  • 17. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <title>Stock Script</title> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <script type="text/javascript" src="getxmlhttprequest.js"> </script> <script type="text/javascript" src="example18-2.js"> </script> </head> ...
  • 18. body> <h2>Fruit Stock Information:</h2> <form action="" method="post"> <p> <label for="strStock">Stock Query: </label> <input type="text" name="strStock" id="strStock"/> </p> <p> <input type="button" value="Check" onclick="startJS();"/> </p> <div id="strStockResult"></div> </form> </body> </html>
  • 19. AJAX –AJAX – connectconnect to server,to server, sendsend requestrequest function startJS() { xhrequest = null; try { xhrequest = getXMLHttpRequest(); } catch(error) { document.write("Cannot run Ajax code using this browser"); } if(xhrequest != null) { JavaScript gets a reference to any element in a page using DOM API // get form values ID Attribute var strStock = document.getElementById("strStock").value; var strUrl = "example18-2.php??strStock=" + strStock; xhrequest.onreadystatechange = changePagechangePage; Php script +query xhrequest.open("GETGET", strUrl, true); xhrequest.send(null); } }
  • 20. function changePage() { if (xhrequest.readyState == 44 && xhrequest.status == 200200) { var strResponsestrResponse = xhrequest.responseText; document.getElementById("strStockResult").innerHTML = strResponsestrResponse; } }
  • 21. function getXMLHttpRequest() { var xhrequest = null; open window in browser if(window.XMLHttpRequestXMLHttpRequest) { property s present // If IE7, Mozilla, Safari, etc: Use native object try { xhrequest = new XMLHttpRequest(); return xhrequest; use native scripting } catch(exception) {ss // OK, just carry on looking } }
  • 22. Steps of AjaxSteps of Ajax A client event occurs. An XMLHttpRequest object is created. The XMLHttpRequest object is configured. The XMLHttpRequest object makes an asynchronous request to the Webserver. The Webserver returns the result containing XML document. The XMLHttpRequest object calls the callback() function and processes the result. The HTML DOM is updated.