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

Slides:



Advertisements
Similar presentations
1 AJAX – Asynchronous JavaScript and XML – Part II CS , Spring 2010.
Advertisements

© 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.
1 JavaScript & AJAX CS , Spring JavaScript.
14-Jul-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 CS , Winter 2007/8. 2 JavaScript.
More APIs: Web Services CMPT 281. Announcements Project milestone Lab: – Web services examples.
Chapter 6 DOJO TOOLKITS. Objectives Discuss XML DOM Discuss JSON Discuss Ajax Response in XML, HTML, JSON, and Other Data Type.
Internet Applications Spring Review Last week –MySQL –Questions?
Interactive Web Application with AJAX
Introduction to AJAX AJAX Keywords: JavaScript and XML
Ajax (Asynchronous JavaScript and XML). AJAX  Enable asynchronous communication between a web client and a server.  A client is not blocked when an.
Ajax Basics The XMLHttpRequest Object. Ajax is…. Ajax is not…. Ajax is not a programming language. Ajax is not a programming language. Ajax is a methodology.
CSCI 6962: Server-side Design and Programming Introduction to AJAX.
Lecture 12 – AJAX SFDV3011 – Advanced Web Development Reference: 1.
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.
XP New Perspectives on XML, 2 nd Edition Tutorial 10 1 WORKING WITH THE DOCUMENT OBJECT MODEL TUTORIAL 10.
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.
XMLHttpRequest Object When Microsoft Internet Explorer 5.0 introduced a rudimentary level of XML support, an ActiveX library called MSXML was also introduced,
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 محمد احمدی نیا 2 Of 27 What is AJAX?  AJAX = Asynchronous JavaScript and XML.  AJAX is not a new programming language, but.
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.
SE-2840 Dr. Mark L. Hornick 1 Introduction to Ajax Asynchronous Javascript And XML.
AJAX and REST. Slide 2 What is AJAX? It’s an acronym for Asynchronous JavaScript and XML Although requests need not be asynchronous It’s not really a.
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.
INNOV-2: Build a Better Web Interface Using AJAX Chris Morgan Pandora Software Systems
 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?
Javascript AJAX HTML WEB SERVER Asynchronous. Javascript HTML events DOM – document object model browser internal view of html page compute.
JavaScript, Sixth Edition Chapter 11 Updating Web Pages with Ajax.
JavaScript and Ajax Week 10 Web site:
CITA 330 Section 10 Web Remoting Techniques. Web Remoting Web Remoting is a term used to categorize the technique of using JavaScript to directly make.
NCCUCS 軟體工程概論 Lecture 5: Ajax, Mashups April 29, 2014.
AJAX. Objectives Understand and apply AJAX Using AJAX in DOJO library.
Open Solutions for a Changing World™ Eddy Kleinjan Copyright 2005, Data Access WordwideNew Techniques for Building Web Applications June 6-9, 2005 Key.
Ajax & Client-side Dynamic Web Gunwoo Park (Undergraduate)
JavaScript and Ajax (Ajax Tutorial)
CSE 154 Lecture 11: AJAx.
CS 371 Web Application Programming
AJAX and REST.
Subbu Allamaraju BEA Systems Inc
XMLHttp Object.
AJAX – Asynchronous JavaScript and XML
AJAX.
CSE 154 Lecture 11: AJAx.
CSE 154 Lecture 22: AJAX.
AJAX Robin Burke ECT 360.
Ajax 28-Feb-19.
Chengyu Sun California State University, Los Angeles
Ajax 6-Apr-19.
AJAX CS-422 Dick Steflik.
Presentation transcript:

AJAX Asynchronous JavaScript and XML

AJAX An interface that allows for the HTTP communication without page refreshment Web pages are loaded into an object within the script (e.g., JavaScript) execution and integrated with the page content Thus, the Web page can communicate with the server without refreshing the whole page

An Example

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

Constructing an XMLHttpRequest For Mozilla (+IE7.0): For Microsoft Internet Explorer (<7.0): var request = new XMLHttpRequest(); var request = new ActiveXObject("Microsoft.XMLHTTP");

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

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

Reading the Response 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.statusrequest.statusText request.getAllResponseHeaders() request.getResponseHeader("header")

Jokes... 2 slides ahead... An Example

Select a Joke: Joke 1 Joke 2 Joke 3 An Example (cont'd)

var jDiv; function init() { jDiv = document.getElementById("jokediv");} function setJoke(value) { request = new XMLHttpRequest(); request.open("GET","joke"+value+".txt",false); request.send(null); if(request.status==200){ jDiv.innerHTML=request.responseText; } else {jDiv.innerHTML = " Cannot load joke... ";} }

Asynchronous Requests Reading of a Web page can take a long time during which the browser is blocked Solution: launch the request asynchronously That is, the execution continues after send is called without waiting for it to complete When the request is completed, a predefined function is called request.open("method","URL",true)

XMLHttpRequest States The XMLHttpRequest goes through several states: In the request configuration, you can define a function to call upon state change: 0 0 not initialized 1 1 loading 2 2 loaded 3 3 interactive 4 4 complete request.onreadystatechange = functionName

XMLHttpRequest States (cont) Use request.readyState to get the current state of the request Use request.abort() to stop the request

var request; function setJoke(value) { request = new XMLHttpRequest(); request.open("GET","joke"+value+".txt",true); request.onreadystatechange = updateJokeDiv; request.send(null); } An Example

function updateJokeDiv() { if(request.readyState<4) { jokeDiv.innerHTML = " Loading... "; return; } if(request.status==200) { jokeDiv.innerHTML = request.responseText; } else { jokeDiv.innerHTML = " Cannot load joke! "; } } An Example (cont'd)

Integrating AJAX and XML using DOM The next example shows how XML data can be parsed and added into the content of your page

Country List … Select a Continent: XML+AJAX Example

Asia Africa Europe XML+AJAX Example (cont'd)

function init() { continents = document.getElementById("continenetList"); countries = document.getElementById("countryList"); } function loadCountries() { var xmlURL = "countries-"+continents.value+".xml"; var request = new XMLHttpRequest(); request.onreadystatechange = updateCountries; request.open("GET",xmlURL,true); request.send(null); } XML+AJAX Example (cont'd)

function updateCountries() { if(request.readyState==4) { while(countries.length>0){countries.remove(0);} if(request.status==200) { var names = request.responseXML.getElementsByTagName("name"); for(var i=0; i<names.length; ++i) { option = document.createElement("option"); option.text=option.value=names[i].firstChild.nodeValue; countries.appendChild(option);} }}} XML+AJAX Example (cont'd)