1 JavaScript & AJAX – Part II CS 236607, Spring 2008.

Slides:



Advertisements
Similar presentations
JQUERY/AJAX ALIREZA KHATAMIAN DELARAM YAZDANSEPAS.
Advertisements

AJAX Asynchronous JavaScript and XML. AJAX An interface that allows for the HTTP communication without page refreshment Web pages are loaded into an object.
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.
IS 360 Course Introduction. Slide 2 What you will Learn (1) The role of Web servers and clients How to create HTML, XHTML, and HTML 5 pages suitable for.
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,
Ajax / Rich Internet Applications ICW Lecture 21 Errol Thompson.
Cloud Computing Lecture #7 Introduction to Ajax Jimmy Lin The iSchool University of Maryland Wednesday, October 15, 2008 This work is licensed under a.
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.
Competence Development Introduction to AJAX. What is AJAX? AJAX = Asynchronous JavaScript and XML For creating interactive web applications – Exchanging.
Prof. James A. Landay University of Washington Spring 2008 Web Interface Design, Prototyping, and Implementation Rich Internet Applications: AJAX, Server.
JQuery CS 268. What is jQuery? From their web site:
Internet Applications Spring Review Last week –MySQL –Questions?
Interactive Web Application with AJAX
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
CS 4720 RESTfulness and AJAX CS 4720 – Web & Mobile Systems.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
CSCI 6962: Server-side Design and Programming Introduction to AJAX.
Lecture 12 – AJAX SFDV3011 – Advanced Web Development Reference: 1.
AJAX and Java ISYS 350. AJAX Asynchronous JavaScript and XML: – Related technologies: JavaScript, Document Object Model, XML, server-side script such.
1 Dr Alexiei Dingli XML Technologies XML Advanced.
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,
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 VS Flex A comparison based on shopping cart implementation PoHsu Yeh py2157.
Web Technologies Lecture 7 Synchronous vs. asynchronous.
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.
CHAPTER 13 COMMUNICATING WITH AJAX. LEARNING OBJECTIVES AJAX, which stands for Asynchronous JavaScript and XMLprovides a way for a browser to send and.
AJAX. Overview of Ajax Ajax is not an API or a programming language Ajax aims to provide more responsive web applications In normal request/response HTTP.
CHAPTER 8 AJAX & JSON WHAT IS AJAX? Ajax lets you…
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 CS456 Fall Examples Where is AJAX used? Why do we care?
Introduction to AJAX MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/4/2016.
JavaScript and Ajax Week 10 Web site:
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.
Open Solutions for a Changing World™ Eddy Kleinjan Copyright 2005, Data Access WordwideNew Techniques for Building Web Applications June 6-9, 2005 Key.
CSE 154 Lecture 11: AJAx.
Not a Language but a series of techniques
CS 371 Web Application Programming
Data Virtualization Tutorial… CORS and CIS
AJAX and REST.
AJAX – Asynchronous JavaScript and XML
AJAX.
CSE 154 Lecture 11: AJAx.
IS 360 Course Introduction
DWR: Direct Web Remoting
CSE 154 Lecture 22: AJAX.
AJAX Robin Burke ECT 360.
ISC440: Web Programming 2 AJAX
Lecture 12: The Fetch Api and AJAx
AJAX CS-422 Dick Steflik.
Lecture 12: The Fetch Api and AJAx
DR. JOHN ABRAHAM PROFESSOR UTPA
Chengyu Sun California State University, Los Angeles
Ajax and JSON Jeremy Shafer Department of MIS Fox School of Business
Chengyu Sun California State University, Los Angeles
Ajax and JSON Jeremy Shafer Department of MIS Fox School of Business
Presentation transcript:

1 JavaScript & AJAX – Part II CS , Spring 2008

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

Select a Joke: Joke 1 Joke 2 Joke 3 An Example (Cont.)

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... ";} } What if we didn’t get yet the response in this stage?

5 Example (Cont.) Our examples use “false" in the third parameter of open().  This parameter specifies whether the request should be handled asynchronously. True means that the script continues to run after the send() method, without waiting for a response from the server. Let’s see how it works, and how it is saved on the Tomcat server.

6 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)

7 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

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

9 var request; function setJoke(value) { request = new XMLHttpRequest(); request.open("GET","joke"+value+".txt",true); request.onreadystatechange = updateJokeDiv(); request.send(null); } Asynchronous 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.)

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

12 Country List … Select a Continent: XML+AJAX Example

Asia Africa Europe XML+AJAX Example (Cont.)

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.)

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.)

16 JavaScript Libraries To reduce the amount of JavaScript code you need to write for Ajax requests, and to make sure that those requests succeed across multiple browsers, one better use a JavaScript library that neatly encapsulates those details and sharp edges in convenient JavaScript objects. The Prototype Library is one good basic option The Prototype Library jQuery is a more advanced option jQuery ZK is even more advanced (and has JSP integration) ZK JavaScript Frameworks Comparison (Wikipedia) JavaScript Frameworks Comparison

17 Resources DaveFancher.com Hebrew University Course javapassion.com W3 Schools Wikipedia Core JavaServer Faces(2nd Edition) / David Geary, Cay S. Horstmann