AJAX (Unit 3part 2)
AJAX (Unit 3part 2)
TECHNOLOGY
Contents
Introduction to AJAX
Working of AJAX
Purpose of AJAX
Data Exchange in AJAX
History of AJAX
Structure and C/S Process
Pros and Cons of AJAX
Introduction to
AJAXstands for Asynchronous Javascript And
• Ajax
Xml.
• Ajax is just a means of loading data from the
server and selectively updating parts of a web
page without reloading the whole page.
Technologies Used
AJAX uses:
• Javascript (for altering the page)
• XML (for information exchange)
• ASP or JSP (server side)
Data Exchange in AJAX
• In AJAX:
C/S Processes
Most of the time client requires two files
Html page: handles GUI and calls a function of JavaScript.
JavaScript: handles the business logic of the system
In JavaScript, a request is sent by client and response is
taken from server via XMLHTTP object
Response of server should be returned in xml file structure
Only requested data is returned
XMLHTTP Object
• The object that is used to connect to the remote server is called
XMLHTTP.
• It resembles the Java’s URL object that is used to
access a specific URL and get the contents.
For IE 5.5:
objXmlHttp=new ActiveXObject(“Microsoft.XMLHTTP”)
For Mozilla:
objXmlHttp=new XMLHttpRequest()
Sending and Retrieving information
• After creating the object, we can send information to the web server and
get
the answer using this object’s functions:
• GET METHOD
• POST METHOD
Retrieving information
We get the returned value with the
property:
“xmlHttp.responseText”.
Perform behind the scenes to update portions of a webpage without having to reload the
XMLHttpRequest
whole page. Based on:object - communicate with server
JavaScript/DOM - display/manipulate
CSS - information Style it to make it
XML - look nice Format data for
transfering
AJAX - readyState
readyState statuses:
0: request not initialized
1: server connection established
2: request received
3: processing request
4: request finished and
response is ready
status:
200 = "OK"
404 = Page not found
Pros/Cons
• Advantages:
– Independent of server technology.
– Apart from obtaining the XMLHTTP object, all processing is
same for all browser types, because Javascript is used.
– Permits the development of faster and more interactive web
applications.
• Disadvantages:
– The back button problem. People think that when they press
back button, they will return to the last change they made,
but in AJAX this doesn not hold.
– Possible network latency problems. People should be given
feedback about the processing.
– Does not run on all browsers.
Create a simple XMLHttpRequest, and retrieve data from a TXT file