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.

More Related Content

What's hot

Ajax ppt - 32 slides
Ajax ppt - 32 slidesAjax ppt - 32 slides
Ajax ppt - 32 slides
Smithss25
 
Xampp Workshop
Xampp WorkshopXampp Workshop
Xampp Workshop
Anuchit Chalothorn
 
MYSQL - PHP Database Connectivity
MYSQL - PHP Database ConnectivityMYSQL - PHP Database Connectivity
MYSQL - PHP Database Connectivity
V.V.Vanniaperumal College for Women
 
Basic of PHP
Basic of PHPBasic of PHP
Basic of PHP
Nisa Soomro
 
PHP - Introduction to PHP AJAX
PHP -  Introduction to PHP AJAXPHP -  Introduction to PHP AJAX
PHP - Introduction to PHP AJAX
Vibrant Technologies & Computers
 
Php with MYSQL Database
Php with MYSQL DatabasePhp with MYSQL Database
Php with MYSQL Database
Computer Hardware & Trouble shooting
 
Php Error Handling
Php Error HandlingPhp Error Handling
Php Error Handlingmussawir20
 
PHP FUNCTIONS
PHP FUNCTIONSPHP FUNCTIONS
PHP FUNCTIONS
Zeeshan Ahmed
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
Kengatharaiyer Sarveswaran
 
Object Oriented Programming In JavaScript
Object Oriented Programming In JavaScriptObject Oriented Programming In JavaScript
Object Oriented Programming In JavaScript
Forziatech
 
JavaScript - Chapter 3 - Introduction
 JavaScript - Chapter 3 - Introduction JavaScript - Chapter 3 - Introduction
JavaScript - Chapter 3 - Introduction
WebStackAcademy
 
History of JavaScript
History of JavaScriptHistory of JavaScript
History of JavaScript
Rajat Saxena
 
Rich Internet Applications (RIA)
Rich Internet Applications (RIA)Rich Internet Applications (RIA)
Rich Internet Applications (RIA)guest3214e8
 
JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
Asynchronous JavaScript Programming
Asynchronous JavaScript ProgrammingAsynchronous JavaScript Programming
Asynchronous JavaScript Programming
Haim Michael
 
Javascript
JavascriptJavascript
Javascript
Rajavel Dhandabani
 

What's hot (20)

Ajax ppt - 32 slides
Ajax ppt - 32 slidesAjax ppt - 32 slides
Ajax ppt - 32 slides
 
Xampp Workshop
Xampp WorkshopXampp Workshop
Xampp Workshop
 
MYSQL - PHP Database Connectivity
MYSQL - PHP Database ConnectivityMYSQL - PHP Database Connectivity
MYSQL - PHP Database Connectivity
 
Basic of PHP
Basic of PHPBasic of PHP
Basic of PHP
 
Php introduction
Php introductionPhp introduction
Php introduction
 
Php
PhpPhp
Php
 
PHP - Introduction to PHP AJAX
PHP -  Introduction to PHP AJAXPHP -  Introduction to PHP AJAX
PHP - Introduction to PHP AJAX
 
Php with MYSQL Database
Php with MYSQL DatabasePhp with MYSQL Database
Php with MYSQL Database
 
Php Error Handling
Php Error HandlingPhp Error Handling
Php Error Handling
 
Lesson 5 php operators
Lesson 5   php operatorsLesson 5   php operators
Lesson 5 php operators
 
PHP FUNCTIONS
PHP FUNCTIONSPHP FUNCTIONS
PHP FUNCTIONS
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Object Oriented Programming In JavaScript
Object Oriented Programming In JavaScriptObject Oriented Programming In JavaScript
Object Oriented Programming In JavaScript
 
JavaScript - Chapter 3 - Introduction
 JavaScript - Chapter 3 - Introduction JavaScript - Chapter 3 - Introduction
JavaScript - Chapter 3 - Introduction
 
Ajax Ppt
Ajax PptAjax Ppt
Ajax Ppt
 
History of JavaScript
History of JavaScriptHistory of JavaScript
History of JavaScript
 
Rich Internet Applications (RIA)
Rich Internet Applications (RIA)Rich Internet Applications (RIA)
Rich Internet Applications (RIA)
 
JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
 
Asynchronous JavaScript Programming
Asynchronous JavaScript ProgrammingAsynchronous JavaScript Programming
Asynchronous JavaScript Programming
 
Javascript
JavascriptJavascript
Javascript
 

Similar to Ajax Lecture Notes

Ajax Introduction
Ajax IntroductionAjax Introduction
Ajax Introduction
Oliver Cai
 
Ajax
AjaxAjax
Ajax tutorial
Ajax tutorialAjax tutorial
Ajax tutorialKat 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
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
Yoga Raja
 
AJAX
AJAXAJAX
AJAX
AJAXAJAX
AJAX
AJAXAJAX
Unit-5.pptx
Unit-5.pptxUnit-5.pptx
Unit-5.pptx
itzkuu01
 
JavaScript Web Development
JavaScript Web DevelopmentJavaScript Web Development
JavaScript Web Development
vito jeng
 
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
Marcos Caceres
 

Similar to Ajax Lecture Notes (20)

Ajax
AjaxAjax
Ajax
 
Ajax
AjaxAjax
Ajax
 
Ajax Introduction
Ajax IntroductionAjax Introduction
Ajax Introduction
 
Ajax
AjaxAjax
Ajax
 
Ajax tutorial
Ajax tutorialAjax tutorial
Ajax tutorial
 
SynapseIndia dotnet development ajax client library
SynapseIndia dotnet development ajax client librarySynapseIndia dotnet development ajax client library
SynapseIndia dotnet development ajax client library
 
Building Applications Using Ajax
Building Applications Using AjaxBuilding Applications Using Ajax
Building Applications Using Ajax
 
Ajax tutorial by bally chohan
Ajax tutorial by bally chohanAjax tutorial by bally chohan
Ajax tutorial by bally chohan
 
Ajax
AjaxAjax
Ajax
 
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
 
Ajax
AjaxAjax
Ajax
 
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
 
Unit-5.pptx
Unit-5.pptxUnit-5.pptx
Unit-5.pptx
 
JavaScript Web Development
JavaScript Web DevelopmentJavaScript Web Development
JavaScript Web Development
 
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
 

More from Santhiya Grace

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
 

More from Santhiya Grace (10)

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

Recently uploaded

HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
Jayaprasanna4
 
Courier management system project report.pdf
Courier management system project report.pdfCourier management system project report.pdf
Courier management system project report.pdf
Kamal Acharya
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
Kamal Acharya
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
AafreenAbuthahir2
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
ankuprajapati0525
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
TeeVichai
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
MuhammadTufail242431
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 

Recently uploaded (20)

HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
 
Courier management system project report.pdf
Courier management system project report.pdfCourier management system project report.pdf
Courier management system project report.pdf
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 

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.