Escolar Documentos
Profissional Documentos
Cultura Documentos
09119001052
What is AJAX ?
Asynchronous Javascript and XML. Not a stand-alone language or technology. It is a technique that combines a set of known technologies in order to create faster and more user friendly web pages. It is a client side technology.
Purpose of AJAX
Prevents unnecessary reloading of a page.
When we submit a form, although most of the page remains the same, whole page is reloaded from the server. This causes very long waiting times and waste of bandwidth. loading only the necessary information, and making only the necessary changes on the current page without reloading the whole page.
The list which appears when we write a single letter in the search box is an example of AJAX
1 browser 2
http request
3 server-side systems
web server UI
html + css data
5
browser replaces view with data sent from server
4
data is returned in response to the request
five stages of each interaction. Will unpack how this actually works later on.
browser browser
JavaScript calls
server-side systems
request
UI UI
Ajax engine
html + css + xml data data mgmt
web server
How does this work? The next slides explain whats happing under the browser hood to support the Ajax approach.
browser
data and images, and knows how to format and display it.
request
browser
UI
UI
data
data stores. Browser knows how to save and manage data it downloads.
how it all works -1 User clicks on a link: rendering engine / browser sends of a request document. 3 Data comes back browser for a 2
request
UI
browser
request
UI
XML data
JavaScript code
data
XML data support. Browsers can now store XML data, and access / manipulate from JavaScript programs via the JavaScript engine.
XMLHttpRequest()
Ajax is a pattern for building JavaScript Engine applications on the browser. A The pattern is: C A Use JavaScript to control the show. XML HTML / CSS UI JavaScript Use it to asynchronously data data Code request and retrieve data from B remote servers, whenever the the Ajax other engine data (e.g. program thinks this is a good images) idea (i.e. not just when the user does something), B Use XML to send numerical or text-style data to the browser. Then use JavaScript to extract data from the XML,
C Use HTML and CSS for display: manipulate this using JavaScript.
A
control JavaScript
B
data XML, other formats (e.g. images)
C
display HTML and CSS
browser browser
HTML rendering engine
XMLHttpRequest()
server-side systems
request
UI
UI UI
XML data
Ajax engine
web server
html + css + xml data data mgmt
Technologies Used
AJAX uses:
Javascript (for altering the page) XML (for information exchange) ASP or JSP (server side)
Alternative Technologies
Not a technology, but a combination of technologies. Technologies with similar tasks: URLConnection, ASP and JSP Other technologies returns whole page and client loads it. Only necessary data is returned and that part is updated
XMLHTTP Object
The object that is used to connect to the remote server is called XMLHTTP. It resembles the Javas URL object that is used to access a specific URL and get the contents.
Sending information
After creating the object, we can send information to the web server and get the answer using this objects functions: GET METHOD: xmlhttp.open(GET, url, true) xmlhttp.send() POST METHOD: xmlhttp.open("POST", url, true) xmlhttp.send(date=11112006&name=Ali") Third argument tells that data will be processes asynchronously. When server responds, the OnReadyStateChange event handler will be called.
Retrieving information
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.