introduction to ajax

18
August 05,2011 Raja.V Introduction to AJAX

Upload: raja-vuppu

Post on 21-Dec-2014

657 views

Category:

Technology


0 download

DESCRIPTION

Introduction to AJAX for beginners.

TRANSCRIPT

Page 1: Introduction to ajax

August 05,2011 Raja.V

Introduction to AJAX

Page 2: Introduction to ajax

RECAP

Page 3: Introduction to ajax

Classic Web applicationAJAX BasicsClassic vs AJAXHow AJAX Works ?

Objectives

Page 4: Introduction to ajax

“Click, wait, and refresh” user interaction- Page refreshes from the server needed for all events, data submissions, and navigation- The user has to wait for the response

Synchronous “request/response” communication model

Browser always initiates the requestUses HttpServletRequest

Classic Web application

Page 5: Introduction to ajax

Slow ResponseExcessive server load and bandwidth

consumptionLoss of operation context during refresh

Disadvantages of classic web application

Page 6: Introduction to ajax

A…..J…….A……XAJAX is not a programming

language/technology. Ajax is a design approach and a set of

techniques for creating a highly interactive user experience for web applications.

Makes Applications faster and user friendly.

Introduction

Page 7: Introduction to ajax

Google Maps- http://maps.google.com/

Google Suggest- http://www.google.com/

Gmail- http://gmail.com/

Real-Life Examples of AJAX

Page 8: Introduction to ajax

AJAX uses XMLHttpRequestJavaScript communicates directly with the server,

through the JavaScript XMLHttpRequest object .

With an XMLHTTPRequest, a web page can make a request to, and get a response from a web server - without reloading the page.

AJAX Basics

Page 9: Introduction to ajax

AJAX Applications Are: 3-tier client/server apps

Browser ↔ App Server ↔ Data Source Event driven

User clicks, user drags, user changes data Graphics Intensive

Visual Effects, Rich Visual Controls Are Data Oriented

Users are manipulating and entering data Are Complex

Pages hold many more controls and data than page-oriented applications

Multiple Master-Detail Relationships in one page

A New Way of Building Applications

Page 10: Introduction to ajax

Classic vs AJAX

Page 11: Introduction to ajax

onreadystatechangereadyStatestatusresponseTextresponseXML

AJAX Terminology

Page 12: Introduction to ajax

JavaScript– Define an object for sending XMLHTTP requests– Initiate request

• Get request object• Designate a request handler function

– Supply as onreadystatechange attribute of request• Initiate a GET or POST request• Send data

– Handle response• Wait for readyState of 4 and HTTP status of 200• Extract return text with response Text or responseXML• Do something with result

HTML– Loads JavaScript– Gives ids to input elements that will be read by script

How AJAX works ?

Page 13: Introduction to ajax

var request;function getRequestObject() {if (window.ActiveXObject) { //IE5, IE6

return(new ActiveXObject("Microsoft.XMLHTTP"));} else if (window.XMLHttpRequest) {//IE7+, Firefox,

…return(new XMLHttpRequest());

} else {return(null);

}}

Define Object

Page 14: Introduction to ajax

function sendRequest() {request = getRequestObject();request.onreadystatechange =

handleResponse;request.open("GET", "message-data.html",

true);request.send(null);}

Initiate Request

Page 15: Introduction to ajax

function handleResponse() {if (request.readyState == 4 && request. status

== 200) {alert(request.responseText);}}

Handling Response

Page 16: Introduction to ajax

AJAX ready states0 - Uninitialized1 - Loading2 - Loaded3 - Processing4 - Request Finished

AJAX status200 - ok404 – Page Not Found

Page 17: Introduction to ajax

Ajax: A New Approach to Web Applicationshttp://www.adaptivepath.com/publications/essays/archives/

000385.phpwww.ajaxmatters.comwww.ajaxian.comwww.ajaxpatterns.org

References

Page 18: Introduction to ajax