Professional Documents
Culture Documents
UNIT 5 WT Ajax
UNIT 5 WT Ajax
ARCHITECTURE
⬥AJAX - Asynchronous JavaScript and XML.
⬥A new technique for creating better, faster,
and more interactive web applications with the
AJAX help of XML, HTML, CSS, and Java Script.
⬥Ajax uses
■ XHTML for content
■ CSS for presentation
■ Document Object Model and JavaScript for
dynamic content display.
2
3 4
AJAX CLIENT SERVER
ARCHITECTURE
⬥AJAX is based on the following open
standards:
■ Browser-based presentation using HTML and
Cascading Style Sheets (CSS).
■ Data is stored in XML format and fetched from
the server.
■ Behind-the-scenes data fetches using
XMLHttpRequest objects in the browser.
■ JavaScript to make everything happen.
5 6
⬥The XMLHttpRequest object is used to ⬥All modern browsers (Chrome, IE7+, Firefox,
exchange data with a server behind the Safari, and Opera) have a built-in
scenes. XMLHttpRequest object.
⬥ This means that it is possible to update parts ■ Syntax for creating an XMLHttpRequest object:
of a web page, without reloading the whole ■ variable = new XMLHttpRequest();
page. ⬥Old versions of Internet Explorer (IE5 and
IE6) use an ActiveX Object:
■ variable = new ActiveXObject("Microsoft.XMLHTTP");
7 8
XML HTTP REQUEST OBJECT XML HTTP REQUEST OBJECT
11 12
XML HTTP REQUEST OBJECT ⬥A simple GET request:
⬥Example
xhttp.open("GET", "demo_get.asp", true);
⬥GET is simpler and faster than POST, and can xhttp.send();
be used in most cases. ⬥In the example above, you may get a cached
⬥However, always use POST requests when: result. To avoid this, add a unique ID to the
■ A cached file is not an option (update a file or URL:
database on the server). ⬥Example
■ Sending a large amount of data to the server xhttp.open("GET", "demo_get.asp?t=" +
(POST has no size limitations). Math.random(), true);
■ Sending user input (which can contain unknown xhttp.send();
characters), POST is more robust and secure than
GET. 13 14
15 16
XML HTTP REQUEST OBJECT CALL BACK METHODS
⬥With AJAX, the JavaScript does not have to ⬥The ajaxSuccess( callback ) method attaches
wait for the server response, but can instead: a function to be executed whenever an AJAX
■ execute other scripts while waiting for server request completes successfully. This is an
response Ajax Event.
■ deal with the response when the response ready ⬥Syntax
⬥ $(document).ajaxSuccess( callback )
17 18
⬥Parameters ⬥jQuery
■ callback − The function to execute. The event ■ fast, small, and feature-rich JavaScript library.
object, XMLHttpRequest, and settings used for ■ It makes things much simpler with an easy-to-use
that request are passed as arguments to the API that works across a multitude of browsers
callback. ● HTML document traversal and manipulation
● event handling
● Animation
● Ajax
19 20
CALL BACK METHODS CALL BACK METHODS
21 22
25 26
S.
Methods & Description
N.
S.N
Methods & Description
.
ajaxComplete( callback )
1
Attach a function to be executed whenever an AJAX request completes.
ajaxStart( callback )
2 Attach a function to be executed whenever an AJAX request begins and there is none already
active.
ajaxError( callback )
3
Attach a function to be executed whenever an AJAX request fails.
ajaxSend( callback )
4
Attach a function to be executed before an AJAX request is sent.
ajaxStop( callback )
5
Attach a function to be executed whenever all AJAX requests have ended.
ajaxSuccess( callback )
6
Attach a function to be executed whenever an AJAX request completes successfully.
29