AJAX Introduction by Bhanwar Gupta - HTML preview
Download the book in PDF, ePub, Kindle for a complete version.
which brings us to Ajax
browser XMLHttpRequest()• Ajax is a pattern for building JavaScript Engineapplications on the browser. A• The pattern is:A
A.
Use JavaScript to control the show. C
Use it to asynchronously
UIHTML / CSS XMLJavaScript
request and retrieve data from data data Code –remote servers, whenever the other Bthe Ajaxprogram thinks this is a good
data (e.g. “engine”
idea (i.e. not just when the images)
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.
C
A B C control data display JavaScript XML, other formats HTML and CSS
(e.g. images)Ajax: Pattern
Trigger
Operation
Update
Pattern – O- Matic

• An XMLHTTPRequest object can be created on the client by javascript
• Depending on the web browser (Firefox, various versions of Internet Explorer), the code to create it is different
Ajax : XHR

•
// javascript code for all browsers
•
function getXMLHTTPRequest()
•
{
•
var request = false;
•
try
•
{
•
request = new XMLHTTPRequest( ); // Firefox
•
}
•
catch( err1 )
•
{
•
try
•
{
•
request = new ActiveXObject( “Msxml2.XMLHTTP”);
•
// some IE versions
•
catch( err2 )
•
{
•
try
•
{
•
request = new ActiveXObject( “Microsoft.XMLHTTP”);
•
// some other IE versions
•
}
•
catch( err3 )
•
{
•
request = false;
•
}
•
}
•
}
•
return request;
