NCCUCS 軟體工程概論 Lecture 5: Ajax, Mashups April 29, 2014.

Slides:



Advertisements
Similar presentations
AJAX Presented by: Dickson Fu Dimas Ariawan Niels Andreassen Ryan Dial Jordan Nielson CMPUT 410 University of Alberta 2006.
Advertisements

Asynchronous HTTP request generation in JavaScript (AJAX)
AJAX asynchronous server-client communication. Test.
1 JavaScript & AJAX CS , Spring JavaScript.
Using AJAX Galip Aydin, Ahmet Sayar, and Marlon Pierce Community Grids Lab Indiana University.
Chapter 6 DOJO TOOLKITS. Objectives Discuss XML DOM Discuss JSON Discuss Ajax Response in XML, HTML, JSON, and Other Data Type.
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.
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.
PHP and AJAX ISYS 475. AJAX Asynchronous JavaScript and XML: – JavaScript, Document Object Model, Cascade Style Sheet, XML, server-side script such as.Net,
JavaScript & jQuery the missing manual Chapter 11
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.
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:
Web Mashups -Nirav Shah.
06/10/2015AJAX 1. 2 Introduction All material from AJAX – what is it? Traditional web pages and operation Examples of AJAX use Creating.
Understanding AJAX Hype, Hope, Hurt and Help for the Web MJTS May 4th, 2006 _________________________ Terence Conklin, Conklin Systems
Cross Site Integration “mashups” cross site scripting.
Ajax In Action The Journey into Web2.0 Presented by Eric Pascarello.
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 XMod for Dummies Building DNN Ajax Modules Without Programming Dave McMullen SoCal DNN Users Group 2/7/07 –
Asynchronous Javascript And XML AJAX : an introduction UFCEUS-20-2 : Web Programming.
1 Web Servers (Chapter 21 – Pages( ) Outline 21.1 Introduction 21.2 HTTP Request Types 21.3 System Architecture.
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:
AJAX Asynchronous JavaScript & XML A short introduction.
Chapter 16: Ajax-Enabled Rich Internet Applications with XML and JSON TP2543 Web Programming Mohammad Faidzul Nasrudin.
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.
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 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
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, Sixth Edition Chapter 11 Updating Web Pages with Ajax.
JavaScript and Ajax Week 10 Web site:
Ajax 101 for CF Programmers Randy Brown – Michigan State University
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.
National College of Science & Information Technology.
AJAX Rohan B Thimmappa. What Is AJAX? AJAX stands for Asynchronous JavaScript and XML. AJAX stands for Asynchronous JavaScript and XML. A remote scripting.
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)
Web Mashups -Nirav Shah.
CSE 154 Lecture 11: AJAx.
Not a Language but a series of techniques
CS 371 Web Application Programming
AJAX and REST.
XMLHttp Object.
AJAX – Asynchronous JavaScript and XML
AJAX.
CSE 154 Lecture 11: AJAx.
AJAX and JSP ISYS 350.
CSE 154 Lecture 22: AJAX.
AJAX Robin Burke ECT 360.
JavaScript & AJAX.
ISC440: Web Programming 2 AJAX
JavaScript & jQuery AJAX.
AJAX CS-422 Dick Steflik.
Intro to Ajax Fred Stluka Jan 25, 2006.
Web Technology Even Sem 2015
AJAX and JSP ISYS 350.
Presentation transcript:

NCCUCS 軟體工程概論 Lecture 5: Ajax, Mashups April 29, 2014

NCCU/CS/WebProg Agenda Asynchronous JavaScript and XML – 不必換頁更流暢 Web 2.0 混搭風( Mashup ) 概念為主、技術細節為輔

A J A X Asynchronous JavaScript And XML Based on the XML HTTP Request (XHR) object created by Microsoft Corp. in 1997 AJAX – term coined by James Garrett in February 2005

A J A X Asynchronous JavaScript And XML Why use AJAX? –To provide a desktop-like user interface for Web Applications –Increased user satisfaction: Improved response time No plug-ins or other special installations on the Browser –Reduces redundant content on the Web

What does Asynchronous Mean? 簡單說 : 不必換頁 就可顯示 新內容

EXAMPLES OF AJAX Gmail ( 傳送中 …) Google search suggest Google Map …

Google Search (Traditional)

Google Suggest (AJAX)

Google Map 放大與縮小 上下左右移動

AJAX Client/Server Interaction

How Ajax Works

Ajax 技術細節請見其他文件 NCCU/CS/WebProg

Web 2.0 and Mashup NCCU/CS/WebProg

Web 1.0 vs. Web 2.0 NCCU/CS/WebProg

Web API Web Services (program-to-program) vs. Web Applications (program-to-user) NCCU/CS/WebProg

Simplest Web API: URL Query Strings

Mashup Originated from pop music. A Mashup is a web application or site that combines data from more than one source into a single integrated tool. Content used in Mashup is typically sourced from a third party via a public interface or so called API Web Mashup = API [1] + API [2] + API [N]

Web Mashup genres  Mapping mashups Google Maps, Yahoo Maps, Microsoft Virtual Earth  Video and photo mashups Flickr, Youtube  Search and Shopping mashups eBay, Amazon  News mashups Diggdot.us= Digg.com + Slashdot.org + Del.icio.us Example:

Mashup (Web 2.0)

Putting everything together Your Mashup = API calls + Data Manipulation + UI User Mashup website User Request Website 1 Website 2 API CallDataAPI Call Data Data presentation Data Manipulation

Writing JavaScript Code to use AJAX Extra slides

Using Ajax Browser support –The XMLHttpRequest object Use it to send request to the server program –Let js call php A JavaScript event-handler (function) to process data from the server –onreadystatechange A server-side program to fulfill the client request var requestObj = new XMLHttpRequest();

Browser Support (for IE) By way of the XMLHttpRequest –W3C standard: –Available in IE 7, but not earlier version of IE function getXMLHttpObject(){ if (window.XMLHttpRequest) return new XMLHttpRequest(); if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP"); alert("Your browser does not support AJAX."); return null; } var requestObj = getXMLHttpObject();

Usage of XMLHttpRequest

Setting Up a Request using XMLHttpRequest GET vs. POST requestObj.open('GET', ' true); requestObj.send(null); Warning: The URL requested must be on the same webserver as the webpage making the request. Accessing a “3rd party domain” using the XMLHttpRequest object is illegal (unless you modify the browser security settings). requestObj.open("POST", "/query.cgi") requestObj.send( ); requestObj.open('GET', “query.cgi?name=Bob”, true); requestObj.send(null); Asynchronous

Set up the Event Handler for Server Data We need to set up an event handler to be called when the server responded. Suppose, for example, we have a function named handleResponse that we want to execute when the web server sends our data. We would assign the handler function to our XMLHttpRequest object as follows: requestObj.onreadystatechange = handleResponse; function handleResponse() { … } // call back function

Responding to the Server Data The event handler will be invoked when the ready state of the XMLHttp request object changes. function handleResponse() { if (requestObj.readyState == 4) if (requestObject.status==200) // process the server data... } // call back function State code

Responding to the Server Data How to know if the server data is available? W3C standard: 0. Unintialized. This is the initial status of your request. 1. Open. This is the status of your request after you call the open method. 2. Sent. Your request has been sent, but no information from the web server has been received. 3. Receiving. Your computer is receiving data, the header information is available for processing but additional data (e.g., the actual file) is still being transferred. 4. Loaded. The transfer has been completed.

Responding to the Server Data, MSIE the readyState for MSIE: –0. Unintialized. This is the initial status of your request. –1. Loading. This is the status of your request after you call the send method. –2. Loaded. Your request has been sent and is awaiting processing on the webserver. –3. Interactive. The webserver is processing your request. –4. Completed. The transfer has been completed.

The Server Data (Result) The result is also stored in the XMLHttpRequest object –A text string or an XML file Parse and display data –requestObj.responseXML DOM-structured object –requestObj.responseText One complete string

An Example: Check whether the user name is already in use. For more examples: Please enter a user name, and we’ll check if it is in use. user name :

<input type="text" id="username" name="username" size="15" onkeyup="check_user_exists(this.value);“ /> Example Code function check_user_exists(str) { if (str.length<4) { document.getElementById(“ajax_msg").innerHTML=""; return; } xmlHttp = getXmlHttpObject(); xmlHttp.onreadystatechange=ajax_handler; xmlHttp.open('GET', 'check_user_exists.php?username='+str); xmlHttp.send(null); } New XMLHttpRequestObject();

More Code function ajax_handler() { if (this.readyState == 4) { if (this.responseText == 'username ok!') document.getElementById(‘ajax_msg’).innerHTML = ‘username ok'; else document.getElementById(‘ajax_msg’).innerHTML = this.responseText; } } <?php // check_user_exists.php require 'user_lib.php'; require 'validate.php'; require 'util.php'; if (check_user_exists($username)) echo ' The username you entered is already in use, please try another '; else echo 'username ok!'; ?>

JSON vs. XML XML is quite heavy weight JSON as an alternative –JavaScript Object Notation Please refer to reference web page on moodle, or another set of slides –Json-slides.pdf