Chapter 6 DOJO TOOLKITS. Objectives Discuss XML DOM Discuss JSON Discuss Ajax Response in XML, HTML, JSON, and Other Data Type.

Slides:



Advertisements
Similar presentations
E-Commerce CMM503 – Lecture 8 Stuart Watt Room C2.
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)
Cloud Computing Lecture #7 Introduction to Ajax Jimmy Lin The iSchool University of Maryland Wednesday, October 15, 2008 This work is licensed under a.
Microsoft ASP.NET AJAX - AJAX as it has to be Presented by : Rana Vijayasimha Nalla CSCE Grad Student.
© 2006 by IBM 1 How to use Eclipse to Build Rich Internet Applications With PHP and AJAX Phil Berkland IBM Software Group Emerging.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
Server Side Scripting Norman White. Where do we do processing? Client side – Javascript (embed code in html) – Java applets (send java program to run.
INTRODUCTION TO WEB DATABASE PROGRAMMING
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
CSCI 6962: Server-side Design and Programming Introduction to AJAX.
Step Outside the Box – Part II ColdFusion and Ajax.
ASP.NET + Ajax Jesper Tørresø ITNET2 F08. Ajax Ajax (Asynchronous JavaScript and XML) A group of interrelated web development techniques used for creating.
Ajax Runtime Toolkits IBM Emerging Technologies. What is an AJAX Toolkit/Framework? An AJAX Toolkit/Runtime is more than just XMLHTTPRequest Should includes:
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
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.
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:
Matrix Mapping Tool Sam Gross Internship at Virtual Technology Corporation.
06/10/2015AJAX 1. 2 Introduction All material from AJAX – what is it? Traditional web pages and operation Examples of AJAX use Creating.
1 Geospatial and Business Intelligence Jean-Sébastien Turcotte Executive VP San Francisco - April 2007 Streamlining web mapping applications.
Telerik Software Academy ASP.NET Web Forms Telerik Software Academy ASP.NET Web Forms.
Lecture 9: AJAX, Javascript review..  AJAX  Synchronous vs. asynchronous browsing.  Refreshing only “part of a page” from a URL.  Frameworks: Prototype,
Rails & Ajax Module 5. Introduction to Rails Overview of Rails Rails is Ruby based “A development framework for Web-based applications” Rails uses the.
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.
SYST Web Technologies SYST Web Technologies AJAX.
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.
Module: Software Engineering of Web Applications Chapter 2: Technologies 1.
CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.
AJAX Asynchronous JavaScript and XML 1. AJAX Outline What is AJAX? Benefits Real world examples How it works 2.
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. Ajax  $.get  $.post  $.getJSON  $.ajax  json and xml  Looping over data results, success and error callbacks.
Rich Internet Applications 2. Core JavaScript. The importance of JavaScript Many choices open to the developer for server-side Can choose server technology.
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.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
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 CS456 Fall Examples Where is AJAX used? Why do we care?
1 AJAX. AJAX – Whatzit? Asynchronous (content loading)‏ Javascript (logic & control)‏ And XML (request handling)‏
JQUERY AND AJAX
JavaScript, Sixth Edition Chapter 11 Updating Web Pages with Ajax.
JavaScript and Ajax Week 10 Web site:
Web Services Essentials. What is a web service? web service: software functionality that can be invoked through the internet using common protocols like.
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.
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.
AJAX. Objectives Understand and apply AJAX Using AJAX in DOJO library.
JavaScript and Ajax (Ajax Tutorial)
CSE 154 Lecture 11: AJAx.
Not a Language but a series of techniques
Google Web Toolkit Tutorial
AJAX and REST.
Ajax Design Patterns – Programming Practices in Web Services
AJAX.
CSE 154 Lecture 11: AJAx.
DWR: Direct Web Remoting
CSE 154 Lecture 22: AJAX.
JavaScript & jQuery AJAX.
Lecture 5: Functions and Parameters
AJAX CS-422 Dick Steflik.
Intro to Ajax Fred Stluka Jan 25, 2006.
Chengyu Sun California State University, Los Angeles
Chengyu Sun California State University, Los Angeles
Software Engineering for Internet Applications
Presentation transcript:

Chapter 6 DOJO TOOLKITS

Objectives Discuss XML DOM Discuss JSON Discuss Ajax Response in XML, HTML, JSON, and Other Data Type

OVERVIEW There are many libraries/frameworks that help Ajax Web development and abstract browser differences. The well known programs include JavaScript based Dojo Toolkit, Prototype framework, and Dynamic Web Remoting (DWR) framework, Yahoo UI Library(YUI), and Java based Google Web Toolkit (GWT).Yahoo UI LibraryGoogle Web Toolkit (GWT) Dojo is a popular Open Source, portable DHTML JavaScript toolkit that makes it easier for an Ajax developer to build Ajax requests. Why is Dojo called a toolkit? Dojo not only has a rich collection of libraries for JavaScript and Ajax Web development, but also provides an extensive, reusable, and customizable widget system supporting user defined widgets, an enhanced event handling system, and an io system which simplifies very complicated data transfers between client and server.

Dojo is a cross-browser oriented tool which supports various Web browsers, such as IE, Firefox, and Safari. It also solves Ajax browser incompatibility problems in ordinary JavaScript. Dojo has a set of powerful JavaScript libraries organized in packages. Dojo 0.4 used to have a layered structure library hierarchy to organize all Dojo functionality in packages. Dojo 0.9 and later versions (currently 1.0) simplify the structure where most Dojo functions (Dojo widgets, events, io and others) are available in Dojo core base packages; dijit and dojox (Extended Dojo project) are sitting on top of Dojo core.

Dojo advantages It wraps XMLHttpRequest and makes the request construction and configuration much easier. It frees developers from detailed configuration of Ajax XMLHttpRequest, and from parsing and processing the responses back from the server. Its widget system is available in Dojo core and Dijit namespace packages.

Ajax XML HttpRequest with Dojo A Hello world Dojo Ajax example: The file “data.txt” has a text statement “Welcome to Dojo Ajax!”. This Web application just downloads the content of this text file, places it in the HTML “div” tag “put_here” placeholder, and displays it. Assume the dojo core package dojo.js library is installed in the dojo directory in the root directory under webapps in a Web server such as Apache Tomcat. If you browse this page, the “Welcome to Dojo Ajax” will be displayed in the HTML page.

Here is the HTML file with a xhrGet Ajax request. Dojo Ajax function welcome() { dojo.xhrGet( { url: "data.txt", // The load function is called on successful response from server // It inserts the response to the HTML div “ put_here ” placeholder load: function(response, ioArgs) { dojo.byId("put_here").innerHTML = response; return response; },

Contd…. // The error function displays error message if server does not // respond right error: function(response, ioArgs) {console.error("HTTP status code: ", ioArgs.xhr.status); return response;} }); } //Invoke the welcome function when dojo starts up dojo.addOnLoad(welcome);

Three dojo methods are used: The dojo.htrGet() is a request method provided in dojo core package which facilitates XMLHttpRequest with GET request method type. Dojo.htrPost is another request type method to makes an XMLHttpRequest. List of Dojo supported XMLHttpRequest functions, they all take a property object(po) parameter. dojo.xhrGet(po) dojo.xhrPost(po) dojo.rawXhrPost(po) dojo.xhrPut(po) dojo.rawXhrPut(po) dojo.xhrDelete(po )

The XMLHttpRequest takes many argument properties. You can pass in a Javascript object, which wraps all necessary properties to the xhrget request as shown in the example. The list of common request property arguments: url: String type, "/path/to/myServer.php". URL points to server endpoint. content: Object type, {name: "value"}. These properties will be serialized as name1=value2 and passed in the request. timeout: numeric type; it wait x milliseconds for the response. If this time passes, then the error callback method is invoked. form: dojo.byId("formId"); it extracts form content and sends it to server. handleAs: String type; "text" is default, it can be "json", "javascript", "xml", etc.

sync: Boolean type, default is false. It indicates whether the request should be synchronous (blocking) or asynchronous. headers: Object type specified in {} format. It is used to send additional HTTP headers in the request. load: function(response, ioArgs){}. The load function will be called on a successful response. error: function(response, ioArgs){}. The error function will be called in an error case. handle: function(response, ioArgs){}. The handle function will be called in either the successful or error case.

Example One uses Dojo xhrGet function to get data from the server and partially update the DHTML page without refreshing the whole page, just like all Ajax requests do. The other uses Dojo xhrPost method to post the DHTML form data to the server and receives responses back from the server to partiall update the client page. The next example shows a Dojo xhrPost Ajax request in the following HTML file. The request is sent to a JSP called response.jsp, which will respond to the Ajax xhrPost form request with a provided user name, and say “Hello ”.

Hello User function onclick() { var cl= { // The page that parses the POST request url: "response.jsp", // Name of the Form you want to submit form: 'myForm', // Loads this function if everything went ok load: function (message) { mdiv = dojo.byId("Message"); mdiv.innerHTML = "<div style=\"color:green\">"+message+" "; },

// Call this function if an error happened error: function (error) { console.error ('Error: ', error); } }; dojo.xhrPost(cl); } Example of using xhrpost Enter Name: <input type='text' length="20" name='myName' onkeyup='onclick();'/>

Response.jsp <% String name = request.getParameter("myName"); if (name != null && !name.trim().equals("")) { out.print("Hello " + name + "!"); } else { out.print("You didn't enter a name!"); } %>

Dojo xhrGet request with JSON data JSON data can be easily handled in the Dojo xhrGet() Ajax request. Dojo greatly frees web developers from doing complicated Ajax request configuration and coding, such as parsing and converting the JSON data into a JavaScript object. You just need to specify that the response is handled in JSON format.

Assume the ajaxData.txt file on the server has JSON syntax data as { "Name": "Bill Jones", "Education": { "Undergraduate": "Physics", "Graduate": "CS" }, "Skills": [“Ajax”, “Ruby”] } The following Ajax request retrieves a JSON object and puts parsed information into the with an id of 'json-data'. The XHRGET function takes JSON format argument, which includes server url, data format handleAs, and a load function (called back when response comes back successfully).

Dojo xhrGet <script src='/dojo/dojo/dojo.js' type='text/javascript'> function getJson () { dojo.xhrGet ({ url: " handleAs: 'json', // 'handleAs': ‘JSON’ tells Dojo to parse the data being // retrieved from the URL by eval() function and convert it to a //JavaScript JSON object.

load: function (responseObject) { dojo.byId('json-data').innerHTML = responseobject.skills[0]; }, error: function (error) { console.error('Error: ', error); } }); } Display JSON data

Summary The Dojo toolkit is a very useful and widely used development tool for Ajax and other Web development. It greatly simplifies the JavaScript coding by way of the Dojo supported package library. Specifically, it is much easier to construct an Ajax XMLHttpRequest with Dojo than to use JavaScript. Dojo supports a powerful widget system that lets developers design their own widgets without worrying about browser incompatibility problems.

The JSON standard for transferring data between Web clients and servers is widely accepted by almost all software programming language and script languages. It reduces the parsing complexity of XML formatted data. People who are not familiar with XML DOM API can still easily construct and parse JSON data.