The Document Object Model (DOM) & Asynchronous Javascript And XML (AJAX) : an introduction UFCEKG-20-2 : Data, Schemas and Applications.

Slides:



Advertisements
Similar presentations
1/7 ITApplications XML Module Session 8: Introduction to Programming with XML.
Advertisements

9. AJAX & RIA. 2 Motto: O! call back yesterday, bid time return. — William Shakespeare.
6/3/2015eBiquity1 Tutorial on AJAX Anubhav Kale (akale1 AT cs DOT umbc DOT edu)
Asynchronous HTTP request generation in JavaScript (AJAX)
Chapter 6 DOJO TOOLKITS. Objectives Discuss XML DOM Discuss JSON Discuss Ajax Response in XML, HTML, JSON, and Other Data Type.
DHTML. What is DHTML?  DHTML is the combination of several built-in browser features in fourth generation browsers that enable a web page to be more.
Ajax (Asynchronous JavaScript and XML). AJAX  Enable asynchronous communication between a web client and a server.  A client is not blocked when an.
CGI and AJAX CS-260 Dick Steflik.
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
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.
ASP.NET + Ajax Jesper Tørresø ITNET2 F08. Ajax Ajax (Asynchronous JavaScript and XML) A group of interrelated web development techniques used for creating.
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
HTML DOM.  The HTML DOM defines a standard way for accessing and manipulating HTML documents.  The DOM presents an HTML document as a tree- structure.
1 Document Object Model (DOM) MV4920 – XML 24 September 2001 Simon R. Goerger MAJ, US Army
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.
Lecture 2 : Understanding the Document Object Model (DOM) UFCFR Advanced Topics in Web Development II 2014/15 SHAPE Hong Kong.
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:
AJAX Making Dynamic Web pages more Dynamic Jim Hendricks April 25th, 2006.
06/10/2015AJAX 1. 2 Introduction All material from AJAX – what is it? Traditional web pages and operation Examples of AJAX use Creating.
Client side web programming Introduction Jaana Holvikivi, DSc. School of ICT.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Javascript II DOM & JSON. In an effort to create increasingly interactive experiences on the web, programmers wanted access to the functionality of browsers.
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Scripting with the DOM Ellen Pearlman Eileen Mullin Programming the Web.
Ajax In Action The Journey into Web2.0 Presented by Eric Pascarello.
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)
Asynchronous Javascript And XML AJAX : an introduction UFCEUS-20-2 : Web Programming.
SDPLNotes 3.2: DOM1 3.2 Document Object Model (DOM) n How to provide uniform access to structured documents in diverse applications (parsers, browsers,
INNOV-7: Building a Richer UI for the Browser Chris Skeldon Senior Solution Consultant.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
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.
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.
JavaScript & Introduction to AJAX
What is AJAX ? Asynchronous Javascript and XML. Not a stand-alone language or technology. It is a technique that combines a set of known technologies in.
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.
1 AJAX. AJAX – Whatzit? Asynchronous (content loading)‏ Javascript (logic & control)‏ And XML (request handling)‏
JQUERY AND AJAX
XML DOM Week 11 Web site:
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.
Ajax SUBMITTED BY NITIN RAMANI C.S.E 3 rd Y 5 th S R.N CS SUBMITTED TO PRO. PUSHPARAJ PATEL SIR.
Open Solutions for a Changing World™ Eddy Kleinjan Copyright 2005, Data Access WordwideNew Techniques for Building Web Applications June 6-9, 2005 Key.
DHTML.
What is AJAX ? Asynchronous Javascript and XML.
JavaScript and Ajax (Ajax Tutorial)
AJAX and REST.
XMLHttp Object.
AJAX.
AJAX.
Week 11 Web site: XML DOM Week 11 Web site:
CSE 154 Lecture 22: AJAX.
JavaScript & jQuery AJAX.
MIS JavaScript and API Workshop (Part 3)
Chengyu Sun California State University, Los Angeles
AJAX CS-422 Dick Steflik.
Intro to Ajax Fred Stluka Jan 25, 2006.
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:

The Document Object Model (DOM) & Asynchronous Javascript And XML (AJAX) : an introduction UFCEKG-20-2 : Data, Schemas and Applications

DOM : What is it? An object-based, language-neutral, application programming interface (API) for XML and HTML documents - allows programs and scripts to build documents, navigate their structure, add, modify or delete elements and content - provides a foundation for developing querying, filtering, transformation, rendering etc. applications on top of DOM implementations In contrast to “Serial Access XML” (sax) a good way to think of the DOM is as “Directly Obtainable in Memory” (dom) objects representing the nodes, attributes and content of documents

Based on O-O concepts: methodsmethods (to access or change object’s state) interfacesinterfaces (declaration of a set of methods) objectsobjects (encapsulation of data and methods) Roughly similar to the XSLT/XPath data model  a parse tree Tree-like structure implied by the abstract relationships defined by the programming interfaces; Does not necessarily reflect data structures used by an implementation (but probably does) DOM : What is it? (2)

o Language-independence: DOM interfaces are defined using OMG Interface Definition Language (IDL; Defined in Corba Specification) Corba Specification o Language bindings (implementations of DOM interfaces) defined in the Recommendation for Java and ECMAScriptECMAScript (standardised JavaScript) DOM : What is it? (3)

“Dynamic HTML" is a term used by some vendors to describe the combination of HTML, style sheets and scripts that allows documents to be animated. The W3C has received several submissions from members companies on the way in which the object model of HTML documents should be exposed to scripts. These submissions do not propose any new HTML tags or style sheet technology. The W3C DOM Activity is working hard to make sure interoperable and scripting-language neutral solutions are agreed upon. W3C DOM : Why?

The DOM specification is separated into 3 different parts / levels: Core DOM - standard model for any structured document XML DOM - standard model for XML documents HTML DOM - standard model for HTML documents The DOM defines the objects and properties of all document elements, and the methods (interface) to access them. DOM parts/levels (1)

DOM parts/levels (2)

A simple DOM (html) tree:

Preparing pages for DOM All pages must be well-formed XHTML/HTML5 documents. All pages must include a valid DOCTYPE. All pages must include all text inside valid XHTML/HTML5 elements.

Referencing Objects Objects can be referenced –by their id or name (this is the easiest way, but you need to make sure a name is unique in the hierarchy) –by their numerical position in the hierarchy, by walking the array that contains them –by their relation to parent, child, or sibling (parentNode, previousSibling, nextSibling, firstChild, lastChild or the childNodes array

What is AJAX o Asynchronous Javascript And XML –allows the updating of a web page without doing a page reload creates much nicer user experience o AJAX is not really a technology by itself –combination of Javascript, XML and some server- side scripting to create the XML server-side scripting could be done in PHP,.NET, Java Servlet or Java Server Page (JSP)

Client/server interaction (synchronous)

general technique (simplified model) Web Page Server-side Script requests server-side script to be run script run, XML created XML document returned info parsed from XML / text / json and used to update DOM by Javascript

general technique (showing XMLHTTPRequest)

sending a request for a URL o xmlHttpRequest Object –mozilla tmpXmlHttpObject = new XMLHttpRequest(); –IE tmpXmlHttpObject = new ActiveXObject("Microsoft.XMLHTTP"); o create the URL o tell the browser the name of the function to handle the response o send the url to the server

html + javascript (browser) 3 functions (javascript) : function createRequestObject() { // initialize request object } function makeGetRequest(wordId) { // initiate the request } function processResponse() { // process server response and update dom } html section updated with returned text

processResponse when the document is received by the browser control is transferred to where ever we told it to –xmlHttp.onreadystatechange=processResponse –in this case the function named processResponse

processResponse function processResponse() { //check if the server responded if(http.readyState == 4) { //read and assign the response from the server var response = http.responseText; //do additional parsing of the response, if needed //assign the response to the contents of the tag. document.getElementById('description').innerHTML = response; //If the server returned an error, // message would be shown within the div tag!!. //So it may be worth doing some basic error checking //before setting the contents of the } view full html page

XMLHttpRequest Object Methods: –abort() - stop the current request –getAllResponseHeaders - Returns complete set of headers (labels and values) as a string –getResponseHeader(:headerLabel”) – returns the string value of the requested header field –open(“method”,”URL”) sets a pending request –send(content) – transmits the request –setRequestHeader(“label”,”value”) – sets label/value in the header

(continued) Properties –onreadystatechange - event handler to use –readyState (0-uninitialized, 1-loading, 2-loaded, 3- interactive, 4- complete) –responseText – string version of the data returned –responseXML – DOM compatible document object returned by server –status – http response header code (200 – good) –statusText – string message of status code

server-side script creates a “well formed XML document” sets the content type to text/xml can be written in any language –PHP –ASP –.NET –Java –JSP

sample PHP script $id = $_GET['id']; switch ($id) { case 1: echo 'Astraphobia, also known as …..'; break; case 2: echo 'Arithmophobia is the fear of numbers. …. '; break; case 3: echo 'Ophidiophobia or ophiophobia is a ….. '; break; } view full script

Pros & Cons Pros - Interactivity - Portability Cons - Usability criticisms: - Back button: users generally expect that the back button will undo the last state change. - Bookmarking: users might also expect to be able to bookmark pages retrieve them as they would a static html page. - Response time concerns - Network latency may lead to interface delays that user may accept from a web page but not an ‘application’ - JavaScript? - AJAX requires users to have JavaScript enabled in their browsers. This applies to all browsers that support AJAX except for Microsoft

Popular Javascript Frameworks supporting AJAX Jquery open source Prototype – –open source mootools – –open source extJS open source / commercial