AJAX – Asynchronous JavaScript and XML

Slides:



Advertisements
Similar presentations
AJAX Asynchronous JavaScript and XML. AJAX An interface that allows for the HTTP communication without page refreshment Web pages are loaded into an object.
Advertisements

1 AJAX – Asynchronous JavaScript and XML – Part II CS , Spring 2010.
© Copyright 2008 STI - INNSBRUCK Web Engineering Web Technologies III Lecture XI – 16 th December 2008 Federico M. Facca.
9. AJAX & RIA. 2 Motto: O! call back yesterday, bid time return. — William Shakespeare.
AJAX Presented by: Dickson Fu Dimas Ariawan Niels Andreassen Ryan Dial Jordan Nielson CMPUT 410 University of Alberta 2006.
19-Jun-15 Ajax. The hype Ajax (sometimes capitalized as AJAX) stands for Asynchronous JavaScript And XML Ajax is a technique for creating “better, faster,
1 JavaScript & AJAX – Part II CS , Spring 2008.
Does Ajax suck? CS575 Spring 2007 Chanwit Suebsureekul.
1 JavaScript & AJAX CS , Spring JavaScript.
1 JavaScript & AJAX CS , Winter 2007/8. 2 JavaScript.
Chapter 6 DOJO TOOLKITS. Objectives Discuss XML DOM Discuss JSON Discuss Ajax Response in XML, HTML, JSON, and Other Data Type.
Prof. James A. Landay University of Washington Spring 2008 Web Interface Design, Prototyping, and Implementation Rich Internet Applications: AJAX, Server.
Ajax (Asynchronous JavaScript and XML). AJAX  Enable asynchronous communication between a web client and a server.  A client is not blocked when an.
JavaScript & jQuery the missing manual Chapter 11
CSCI 6962: Server-side Design and Programming Introduction to AJAX.
Lecture 12 – AJAX SFDV3011 – Advanced Web Development Reference: 1.
ASP.NET + Ajax Jesper Tørresø ITNET2 F08. Ajax Ajax (Asynchronous JavaScript and XML) A group of interrelated web development techniques used for creating.
JavaScript, Fourth Edition Chapter 12 Updating Web Pages with AJAX.
AJAX and Java ISYS 350. AJAX Asynchronous JavaScript and XML: – Related technologies: JavaScript, Document Object Model, XML, server-side script such.
Intro to Ajax Fred Stluka Jan 25, /25/2006Intro to AjaxFred Stluka2 What is Ajax? "Asynchronous JavaScript and XML" New name for an old technique:
06/10/2015AJAX 1. 2 Introduction All material from AJAX – what is it? Traditional web pages and operation Examples of AJAX use Creating.
Instructor, Dr. Khalili Bahram Jeevan Kumar Gogineni.
Ajax. –Asynchronous JavaScript and XML –Umbrella term for technologies that often: Use client-side scripting for layout and formatting Use less than full.
AJAX (also known as: XMLHTTP, Remote Scripting, XMLHttpRequest, etc.) Matt Warden.
Lecture 9: AJAX, Javascript review..  AJAX  Synchronous vs. asynchronous browsing.  Refreshing only “part of a page” from a URL.  Frameworks: Prototype,
AJAX Compiled from “AJAX Programming” [Sang Shin] (Asynchronous JavaScript and XML)
Ajax. –Asynchronous JavaScript and XML –Umbrella term for technologies that often: Use client-side scripting for layout and formatting Use less than full.
Asynchronous Javascript And XML AJAX : an introduction UFCEUS-20-2 : Web Programming.
Web Technology Introduction AJAXAJAX. AJAX Outline  What is AJAX?  Benefits  Real world examples  How it works  Code review  Samples.
School of Computing and Information Systems CS 371 Web Application Programming AJAX.
CISC 3140 (CIS 20.2) Design & Implementation of Software Application II Instructor : M. Meyer Address: Course Page:
the acronym for Asynchronous JavaScript and XML.
Ajax for Dynamic Web Development Gregory McChesney.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
 AJAX – Asynchronous JavaScript and XML  Ajax is used to develop fast dynamic web applications  Allows web pages to be updated asynchronously by transferring.
AJAX Asynchronous JavaScript and XML 1. AJAX Outline What is AJAX? Benefits Real world examples How it works 2.
Event Handling & AJAX IT210 Web Systems. Question How do we enable users to dynamically interact with a website? Answer: Use mouse and keyboard to trigger.
CHAPTER 8 AJAX & JSON WHAT IS AJAX? Ajax lets you…
AJAX Use Cases for WSRP Subbu Allamaraju BEA Systems Inc WSRP F2F Meeting, May 2006.
AJAX AJAX Asynchronous JavaScript and XML --- MADHAVI
AJAX – Asynchronous JavaScript And XML By Kranthi Kiran Nuthi CIS 764 Kansas State University.
Web Technology (NCS-504) Prepared By Mr. Abhishek Kesharwani Assistant Professor,UCER Naini,Allahabad.
 AJAX technology  Rich User Experience  Characteristics  Real live examples  JavaScript and AJAX  Web application workflow model – synchronous vs.
AJAX CS456 Fall Examples Where is AJAX used? Why do we care?
PHP and AJAX. Servers and Clients For many years we tried to move as much as possible to the server. Weak clients, poor bandwidth, browser compatibility..
JavaScript and Ajax Week 10 Web site:
NCCUCS 軟體工程概論 Lecture 5: Ajax, Mashups April 29, 2014.
JQuery, JSON, AJAX. AJAX: Async JavaScript & XML In traditional Web coding, to get information from a database or a file on the server –make an HTML form.
AJAX. Objectives Understand and apply AJAX Using AJAX in DOJO library.
Ajax & Client-side Dynamic Web Gunwoo Park (Undergraduate)
Introduction to AJAX Pat Morin COMP Outline What is AJAX? – History – Uses – Pros and Cons An XML HTTP Transaction – Creating an XMLHTTPRequest.
JavaScript and Ajax (Ajax Tutorial)
AJAX and JSON Day 8.
CSE 154 Lecture 11: AJAx.
Not a Language but a series of techniques
CS 371 Web Application Programming
Data Virtualization Tutorial… CORS and CIS
Subbu Allamaraju BEA Systems Inc
XMLHttp Object.
Whether you decide to use hidden frames or XMLHttp, there are several things you'll need to consider when building an Ajax application. Expanding the role.
AJAX.
CSE 154 Lecture 11: AJAx.
CSE 154 Lecture 22: AJAX.
ISC440: Web Programming 2 AJAX
JavaScript & jQuery AJAX.
AJAX CS-422 Dick Steflik.
Intro to Ajax Fred Stluka Jan 25, 2006.
DR. JOHN ABRAHAM PROFESSOR UTPA
Creating dynamic/interactive web pages
AJAX By Prof. B.A.Khivsara
Presentation transcript:

AJAX – Asynchronous JavaScript and XML CS 236369, Spring 2010

Where Were We Before AJAX? Static pages give the illusion of interactivity through standard form submissions. Form submissions result in full page loads.

So, What’s The Problem? Many actions only manipulate small portions of the page but the entire page must be reloaded. Server responses contain the entire page content rather than just the portion being updated. Loading entire pages typically results in several additional HTTP requests for images, style sheets, scripts, and any other content that may be on the page.

AJAX - Asynchronous JavaScript and XML A group of interrelated web development techniques used on the client-side to create interactive web applications / rich Internet applications. With Ajax, web applications can retrieve data from the server asynchronously in the background without interfering with the display and behavior of the existing page. Thus, the Web page can communicate with the server without refreshing the whole page.

Real-Life Examples of AJAX Apps Google maps http://maps.google.com/ Goolgle Suggest (Now integrated in Google’s homepage) http://www.google.com/webhp?complete=1&hl=en Yahoo Maps http://maps.yahoo.com/ Many more…

AJAX Components JavaScript DOM XMLHttpRequest object (XHR) XML

Ajax Fundamentals Ajax uses a three-step process: Request a URL by the JavaScript code – client side. Handle the URL on the server and write to the response – server side. After the response is complete, integrate the response into the DOM (Document Object Model) – client side. In an Ajax request we don't refresh the entire page; instead, we update only part of the page.

The Server side Did we reduce the load on the server? Ajax newcomers sometimes mistakenly believe that Ajax, because it provides a more responsive user interface, reduces server-side traffic. In fact, Ajax applications typically have more server-side traffic because each Ajax request involves a trip to the server. Because those requests are asynchronous, however, Ajax creates the perception of a more responsive UI, though it typically does not reduce the load on the server.

So, How Does It Work? JavaScript is used to: Create and control instances of the XMLHttpRequest (XHR) object. Provide handlers for responses. Manipulate the DOM. The XMLHttpRequest object: Allows scripts to perform HTTP client functionality. Supports GET and POST operations.

Launching HTTP Requests Typically, 3 steps are required: 1. Construct and configure an XMLHttpRequest object 2. Launch the request 3. Process the response

Constructing an XMLHttpRequest In all modern browsers: In older Microsoft browsers (IE 5 and 6): (The XMLHttpRequest object is not specified in any W3C recommendation – it is not a W3C standard) var request = new XMLHttpRequest(); var request = new ActiveXObject("Microsoft.XMLHTTP");

Configuring an XMLHttpRequest request.open("method","URL",isAsynchronous) method is GET, POST, etc. URL must be in the domain of the current (or a relative URL), for security reasons The isAsynchronous boolean parameter will be discussed later request.setRequestHeader("header","value")

request.send(content ) Launching the Request request.send(content ) content is the posted in a POST request content can be null or empty

request.getAllResponseHeaders() request.getResponseHeader("header") Reading the Response The XHR Object request.responseText The response as flat text request.responseXML The response as a (DOM) Document object Available if response Content-Type is text/XML request.status request.statusText request.getAllResponseHeaders() request.getResponseHeader("header")

An Example <html> <head> <title>Jokes</title> <script type="text/javascript"> ... 2 slides ahead ... </script> </head>

An Example (Cont.) <body onload="init(); setJoke()"> <h2>Current date on server:<span id="serverTimeSpan“>? </span><h2> <h1>Select a Joke:</h1> <p><select onchange="presentServerTime();setJoke(value)"> <option value="1" selected="selected">Joke 1</option> <option value="2">Joke 2</option> <option value="3">Joke 3</option> </select></p> <div id="jokediv"></div> </body> </html>

<script type="text/javascript"> var jokeDiv; var timeSpan; function init() { jokeDiv=document.getElementById("jokediv"); timeSpan=document.getElementById("serverTimeSpan"); } function presentServerTime() { var request = new XMLHttpRequest(); request.open("GET", "current-time.jsp", false); request.send(null); if (request.status == 200) timeSpan.innerHTML = request.responseText; else timeSpan.innerHTML="Cannot load server time...";

function setJoke(value) { var request = new XMLHttpRequest(); request function setJoke(value) { var request = new XMLHttpRequest(); request.open("GET", "joke" + value + ".txt", false); request.send(null); if (request.status == 200) jokeDiv.innerHTML = request.responseText; else jokeDiv.innerHTML = "Cannot load joke..."; </script>

current-time.jsp <%= new java.util.Date() %> <% long t0,t1; t0=System.currentTimeMillis(); do{ t1=System.currentTimeMillis(); { while (t1-t0<3000);//wait for 3 seconds %>

Example (Cont.) Our examples use “false" in the third parameter of open(). This parameter specifies whether the request should be handled asynchronously. As you can notice by running this example, the joke only appear after the JSP response is received. True means that the script continues to run after the send() method, without waiting for a response from the server.

To be continued…