J.Holvikivi 1 Ajax & scripts Jaana Holvikivi Metropolia.

Slides:



Advertisements
Similar presentations
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
Advertisements

HTTP HyperText Transfer Protocol. HTTP Uses TCP as its underlying transport protocol Uses port 80 Stateless protocol (i.e. HTTP Server maintains no information.
AJAX Presented by: Dickson Fu Dimas Ariawan Niels Andreassen Ryan Dial Jordan Nielson CMPUT 410 University of Alberta 2006.
How the web works: HTTP and CGI explained
Web architecture Dr Jim Briggs Web architecture.
The World Wide Web and the Internet Dr Jim Briggs 1WUCM1.
XMLHttpRequest Object and XML What we should learn in this lesson –What is the XHR object? –How to create the XHR objects? –XHR object properties –XHR.
Web programming for project students Dr Jim Briggs.
Using AJAX Galip Aydin, Ahmet Sayar, and Marlon Pierce Community Grids Lab Indiana University.
2/9/2004 Web and HTTP February 9, /9/2004 Assignments Due – Reading and Warmup Work on Message of the Day.
Writing All Your Code In OpenEdge Architect Peter van Dam.
The Document Object Model (DOM) & Asynchronous Javascript And XML (AJAX) : an introduction UFCEKG-20-2 : Data, Schemas and Applications.
Web technologies and programming cse hypermedia and multimedia technology Fanis Tsandilas April 3, 2007.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
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.
PHP and AJAX ISYS 475. AJAX Asynchronous JavaScript and XML: – JavaScript, Document Object Model, Cascade Style Sheet, XML, server-side script such as.Net,
1 HTML and CGI Scripting CSC8304 – Computing Environments for Bioinformatics - Lecture 10.
Computers: Information Technology in Perspective By Long and Long Copyright 2002 Prentice Hall, Inc. Going Online Chapter Jaana Holvikivi.
Ruth Betcher Ruth Christie
1 Fall 2006 Florida Atlantic University Department of Computer Science & Engineering COT 6930 Advanced Internet Programming Dr. Roy Levow Day 1.
Lecture 12 – AJAX SFDV3011 – Advanced Web Development Reference: 1.
FTP (File Transfer Protocol) & Telnet
CSC 2720 Building Web Applications Getting and Setting HTTP Headers (With PHP Examples)
CP476 Internet Computing Lecture 5 : HTTP, WWW and URL 1 Lecture 5. WWW, HTTP and URL Objective: to review the concepts of WWW to understand how HTTP works.
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.
1 rfXcel Confidential Copyright 2007 Web Technology JavaScript 12/10/07.
06/10/2015AJAX 1. 2 Introduction All material from AJAX – what is it? Traditional web pages and operation Examples of AJAX use Creating.
CIS 375—Web App Dev II DOM. 2 Introduction to DOM The XML Document ________ Model (DOM) is a programming interface for XML documents. It defines the way.
Ajax. –Asynchronous JavaScript and XML –Umbrella term for technologies that often: Use client-side scripting for layout and formatting Use less than full.
Client side web programming Introduction Jaana Holvikivi, DSc. School of ICT.
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)
1-1 HTTP request message GET /somedir/page.html HTTP/1.1 Host: User-agent: Mozilla/4.0 Connection: close Accept-language:fr request.
Asynchronous Javascript And XML AJAX : an introduction UFCEUS-20-2 : Web Programming.
CISC 3140 (CIS 20.2) Design & Implementation of Software Application II Instructor : M. Meyer Address: Course Page:
SYST Web Technologies SYST Web Technologies AJAX.
IS-907 Java EE World Wide Web - Overview. World Wide Web - History Tim Berners-Lee, CERN, 1990 Enable researchers to share information: Remote Access.
Web Technologies Lecture 1 The Internet and HTTP.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
AJAX Asynchronous JavaScript and XML 1. AJAX Outline What is AJAX? Benefits Real world examples How it works 2.
Summer 2007 Florida Atlantic University Department of Computer Science & Engineering COP 4814 – Web Services Dr. Roy Levow Part 1 – Introducing Ajax.
Overview of Servlets and JSP
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.
Dave Salinas. What is XML? XML stands for eXtensible Markup Language Markup language, like HTML HTML was designed to display data, whereas XML was designed.
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?
WEB1P webarch1 Web architecture Dr Jim Briggs. WEB1P webarch2 What is the web? Distributed system Client-server system Characteristics of clients and.
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 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)
Not a Language but a series of techniques
XMLHttp Object.
AJAX.
AJAX Robin Burke ECT 360.
ISC440: Web Programming 2 AJAX
JavaScript & jQuery AJAX.
Chengyu Sun California State University, Los Angeles
AJAX CS-422 Dick Steflik.
Chengyu Sun California State University, Los Angeles
Chengyu Sun California State University, Los Angeles
Presentation transcript:

J.Holvikivi 1 Ajax & scripts Jaana Holvikivi Metropolia

J.Holvikivi 2 Outline Client - server communication and Ajax applications Javascript in HTML and events DOM Ajax components XMLHTTP request Ajax use

J.Holvikivi 3 Page requests on the Web Internet User workstation Browser: HTML, scripts Database server HTTP request Server HTML pages Program Server CGI HTTP: HTML pages PHP JavaASP SQL Oracle

J.Holvikivi 4 HTTP requests GET /index.html HTTP/1.1 Host: Accept: www/source Accept: text/html Accept: image/gif User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: ) Gecko/ Firefox/ a blank line * The client lists the Multipurpose Internet Mail Extension (MIME) types it will accept in return. Finally, the client sends a blank line indicating it has completed its request.

J.Holvikivi 5 HTTP server response HTTP/ OK Date: Mon, 09 Apr :39:22 GMT Server: Apache/ (Unix) (Red-Hat/Linux) Set-Cookie: fe_typo_user=4f74f6c85b; path=/; domain= Last-Modified: Wed, 08 Jan :11:55 GMT Etag: "3f80f-1b6-3e1cb03b" Accept-Ranges: bytes Content-Length: 438 Connection: close Content-Type: text/html; charset=UTF-8

J.Holvikivi 6 GET and POST methods The difference between these two methods is in the way of sending data to the page: GET method sends data using URL (size limit), POST method sends data through a standard entrance

J.Holvikivi 7 Ajax components Modern browsers Javascript & libraries XMLHttpRequest XHTML & CSS DOM XML Server side programs

J.Holvikivi 8 Page requests: XMLHttpRequest User workstation Browser: Capture event/ Update page Database server XMLHTTPRequest (asynchronous) Server Application (PHP, Java, XSLT, ASP): Request readyState response SQL XML Ajax engine: Create server Request Send Monitor status Get response Process returned data Returned data

J.Holvikivi 9 Scripts and styles on an HTML page HTML STYLE HEAD BODY Javascript SCRIPT STYLEsheet Javascript file

J.Holvikivi 10 Javascript Javascript is always downloaded from the server to the client –Either as a file reference –Or embedded in HTML Javascript is executed on client side. –Less load on server –Example: checks on form input (numeric fields, dates, required fields) Javascript understands the structure of the HTML page (document); DOM

J.Holvikivi 11 What do we get with Ajax? Interactivity in Web user interface –Scrolling and zooming maps without Java applets –Interaction on forms (automatic completion, checking of input, getting assistance, hints, tips) –Update checking (mails) –Customization of pages on-the -fly Imagination and creativity

J.Holvikivi 12 Who is using Ajax? Google suggesthttp:// Amazon: a9.com multiple search options Yahoo!News Gmail Google Maps: tiles, dragging, zooming, push pins

J.Holvikivi 13 Javascript and document structure

J.Holvikivi 14 HTML document Javascript can recognize the tree structure This is a test page Below is a table... Row 1 Cell 1 Row 1 Cell 2 Row 2 Cell 1 Row 2 Cell 2

J.Holvikivi 15 Tree of the page ’This is a test page’ ’Below is a table’ data datadata

J.Holvikivi 16 Document Object Model (DOM) Used by many programming languages (php, java, c#, c++, Javascript…) And understood by browsers (Mozilla, IE, Opera, Safari) XML -document is a collection of nodes that make a hierarchical tree structure The hierarchy is used in navigating the tree to locate information Inefficient use of memory: the tree structure is created in the memory DOM enables adding, moving, deleting and changing of nodes

J.Holvikivi 17 Document tree Ancestor Parent / ancestor SiblingNode Child /descendantAttribute Descendant Namespace

J.Holvikivi 18 Processing of the tree Start with the root node ( document-object) Element properties –firstChild –lastChild –nextSibling –parentNode Methods to navigate the tree –getElementByID(id) –getElementsByName(name) –getElementsByTagName(name) –getAttribute(name)

J.Holvikivi 19 XML DOM Note.xml Tove Jani Reminder Don't forget me this weekend! From

J.Holvikivi 20 var xmlDoc; function loadXML() { //load xml file // code for IE if (window.ActiveXObject) { xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async=false; xmlDoc.load("note.xml"); getmessage(); } // code for Mozilla, Firefox, Opera, etc. else if (document.implementation && document.implementation.createDocument) { xmlDoc=document.implementation.createDocument("","",null); xmlDoc.load("note.xml"); xmlDoc.onload=getmessage; } else { alert('Your browser cannot handle this script'); }

J.Holvikivi 21 continues function getmessage() { document.getElementById("to").innerHTML=xmlDoc.getElementsByTagN ame("to")[0].childNodes[0].nodeValue; document.getElementById("from").innerHTML=xmlDoc.getElementsByTa gName("from")[0].childNodes[0].nodeValue; document.getElementById("message").innerHTML=xmlDoc.getElementsB yTagName("body")[0].childNodes[0].nodeValue; } W3Schools Internal Note To: From: Message:

J.Holvikivi 22 What Ajax is? Javascript CSS XMLHttpRequest-object DOM Ajax (Asynchronous Javascript + XML) is basically a new combination of known technologies The XMLHttpRequest -object contacts the server without user control Ajax technologies are included in browser functions! –no Java installation

J.Holvikivi 23 A Client request with AJAX user web client web server Client request munsivu3.php Server executes munsivu3.php And creates an HTML-reponse, That includes javascript Response contains HTML and Javascript To be displayed on the Browser window Javascript code sends a Server request invisibly Server responds by sending the data Javascript code updates the Web page with data The server can call the data base each time before responding

J.Holvikivi 24 Ajax request Client requests an event handler e.g. onclick=startaReq(); XMLHttpRequest-object is created on client Callback handler is registered Start of request –httpReq.open(”GET”, stringA, true); Sending request –httpReq.send(null); Server executes the request and returns data to the client Client takes either text or xml response –httpReq.responseText –httpReq.responseXML

J.Holvikivi 25 XMLHttpRequest XMLHttpRequest-object –Creation –Methods –Properties Server response handling Errors

J.Holvikivi 26 Creation of XMLHttpRequest Internet Explorer Other browsers if (window.ActiveXObject) { request = new ActiveXObject("Microsoft.XMLHTTP"); if (window.XMLHttpRequest) { request = new XMLHttpRequest();

J.Holvikivi 27 XMLHttpRequest properties onreadystatechange set up of callbackfunction readystatereturns status of request: –0 = uninitialized –1 = loading –2 = loaded –3 = interactive –4 = complete responseTextserver response string responseXMLserver response XML document Statusresponse status code statusText response status text

J.Holvikivi 28 Document parsing error function handleServerResponse() { // read the message from the server var xmlResponse = xmlHttp.responseXML; // IE ja Opera if (!xmlResponse || !xmlResponse.documentElement) throw(”Invalid XML structure:\n”+xmlHttp.responseText); // Firefox var rootNodeName = xmlResponse.documentElement.nodeName; if (rootNodeName == ”parsererror”) throw (”Invalid XML structure:\n”+xmlHttp.responseText); // obtain the XML's document element xmlRoot = xmlResponse.documentElement;

J.Holvikivi 29 The browser in control User workstation Browser: Capture event XMLHTTPRequestServer PHP script: Request readyState response Create Request Send Monitor status Returned data Browser: Update page Get response Process returned data Click button HTML CSS JavaScript functions JavaScript functions