Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 16 Introduction to Ajax.

Slides:



Advertisements
Similar presentations
3rd Annual Plex/2E Worldwide Users Conference Page based on Title Slide from Slide Layout palette. Design is cacorp Title text for Title or Divider.
Advertisements

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 15 Introduction to Rails.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 10 Servlets and Java Server Pages.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 JavaScript and XHTML Documents Programming the World Wide Web Fourth.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 15 Introduction to Rails Programming the World Wide Web Fourth edition.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 9 Using Perl for CGI Programming.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 Cascading Style Sheets Programming the World Wide Web Fourth edition.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 12 Introduction to ASP.NET.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 12 Introduction to ASP.NET Programming the World Wide Web Fourth.
HTML Forms. collect information for passing to server- side processes built up from standard widgets –text-input, radio buttons, check boxes, option lists,
23-Aug-14 HTML/XHTML Forms. 2 What are forms? is just another kind of XHTML/HTML tag Forms are used to create (rather primitive) GUIs on Web pages Usually.
24-Aug-14 HTML Forms. 2 What are forms? is just another kind of HTML tag HTML forms are used to create (rather primitive) GUIs on Web pages Usually the.
MWD1001 Website Production Using JavaScript with Forms.
CIS 4004: Web Based Information Technology Spring 2013
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
Ajax. Overview of Ajax History In the 1990s, most web sites were based on complete HTML pages; each user action required that the page be re-loaded from.
The Web Warrior Guide to Web Design Technologies
1 Cleaning up the Internet Using AJAX, SOAP and Comet CS526 Mike Gerschefske Justin Gray James Yoo 02 May 2006.
Web Development & Design Foundations with XHTML Chapter 9 Key Concepts.
Chapter 6 DOJO TOOLKITS. Objectives Discuss XML DOM Discuss JSON Discuss Ajax Response in XML, HTML, JSON, and Other Data Type.
Chapter 9 Collecting Data with Forms. A form on a web page consists of form objects such as text boxes or radio buttons into which users type information.
1 Web Developer & Design Foundations with XHTML Chapter 6 Key Concepts.
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.
JavaScript & jQuery the missing manual Chapter 11
1 Forms A form is the usual way that information is gotten from a browser to a server –HTML has tags to create a collection of objects that implement this.
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.
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.
XP New Perspectives on XML, 2 nd Edition Tutorial 10 1 WORKING WITH THE DOCUMENT OBJECT MODEL TUTORIAL 10.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
06/10/2015AJAX 1. 2 Introduction All material from AJAX – what is it? Traditional web pages and operation Examples of AJAX use Creating.
Chapter 8 Cookies And Security JavaScript, Third Edition.
JavaScript, Fourth Edition
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 16 Introduction to Ajax.
JavaScript - A Web Script Language Fred Durao
PHP Form Introduction Getting User Information Text Input.
Web Programming Brian Toone 8/27/2014. Outline for today 1.Understanding the architecture of the web 2.Overview of programming languages – Client-side.
Fall 2006 Florida Atlantic University Department of Computer Science & Engineering COP 4814 – Web Services Dr. Roy Levow Part 2 – Ajax Fundamentals.
Rails & Ajax Module 5. Introduction to Rails Overview of Rails Rails is Ruby based “A development framework for Web-based applications” Rails uses the.
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2 Revised by Dr. T. Tran for CSI3140.
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.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
Scripting Languages Client Side and Server Side. Examples of client side/server side Examples of client-side side include: JavaScript Jquery (uses a JavaScript.
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.
HTML Forms.
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…
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 Use Cases for WSRP Subbu Allamaraju BEA Systems Inc WSRP F2F Meeting, May 2006.
AJAX in Ruby-on-Rails. Ruby on Rails and AJAX AJAX can be done with just Javascript Easier if you use libraries –Prototype –SAJAX –jQuery Libraries only.
JavaScript Introduction and Background. 2 Web languages Three formal languages HTML JavaScript CSS Three different tasks Document description Client-side.
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?
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.
Section 10.1 Define scripting
Not a Language but a series of techniques
Subbu Allamaraju BEA Systems Inc
AJAX.
AJAX Robin Burke ECT 360.
ISC440: Web Programming 2 AJAX
PHP and JSON Topics Review JSON.
Presentation transcript:

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 16 Introduction to Ajax

16-2 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 16.1 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 cycles, the browser locks waiting for the response and an entire page must be displayed With Ajax, asynchronous requests may be made and responses are used to update part of a page User can continue to interact with a page while the request is in progress Less data needs to be transmitted Page update is quicker because only a part of a page is modified

16-3 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 16.1 Approaches to Ajax The iframe element can be hidden and it allows asynchronous requests to a server Javascript support allows updating other elements of the page from the frame response Microsoft introduced the XmlDocument and XMLHTML objects which are used to make asynchronous requests directly from JavaScript Other browsers followed this path Most browsers now name the object XMLHttpRequest

16-4 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 16.2 The Application The example application uses the customer information part of the popcorn application As the user enters the zip code information, a request for the corresponding city and state will be made to the server If successful, the information will be filled in the text widgets

16-5 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 16.2 The Form Document The trigger for the request is a blur event on the zip code widget this.value is used by the handler to get the zip code value entered All relevant widgets have the id attribute set for easy access in the JavaScript

16-6 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 16.2 The Request Phase Two functions blur event handler Response processor An XMLHttpRequest object is used to create the request A callback is a function called when a response is received Function receivePlace is the callback The function name is assigned to a property of XMLHttpRequest The open method sets up the request Method parameter, either GET or POST URL parameter with zip code in the URL A parameter signifying asynchronous or not The send method sends the request The getPlace method implements this

16-7 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 16.2 The Response Document The response from the server is created by looking up the zip code A local hash of zip codes is used for simplicity A string with the city and state is sent as the response The example is in PHP

16-8 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 16.2 The Receiver Phase The function that parses the response must have access to the XMLHttpRequest object This cannot be global since there may be multiple outstanding requests at any time The callback becomes an anonymous function which is defined in the getPlace method and keeps references to the XMLHttpRequest object held in a local variable The response handler only acts if the readyState is 4, meaning the response is complete

16-9 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 16.2 Cross-Browser Support Older Microsoft browsers uses a different approach to getting the request object Testing the existence of window.XMLHttpRequest differentiates the browsers In the older browsers new ActiveXObject(Microsoft.XMLHTTP) creates the object needed

16-10 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 16.3 Rails with Ajax The prototype JavaScript library is integrated into Rails Rails and Ajax have some limitations Not all elements can be modified, depending on the browser The div element can be modified Rails and Ajax process Sequence is triggered Data is sent asynchronously to an action handler The action handler creates a response JavaScript in the browser interprets the response

16-11 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 16.3 The Initial Form Document The popcorn example is used here, with the zip code helper The show_form action and document show_form.rhtml are the first contact, providing the form

16-12 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 16.3 Triggering Ajax Ruby provides methods to set up triggers for Ajax processing link_to_remote triggers when a link is activated observe_field is triggered when a widget is changed Method observe_field Takes the name of the widget as a first paramater Several keyword parameters :url where to post, often associated with an :action symbol definition :update associated to the id of the elment whose value is to be changed in response :with specifies a parameter for the HTTP request :frequency specifies how often to check :complete, :success, :failure associate with callbacks used depending on the outpcome of the reuqest

16-13 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 16.3 Example A special tag is used to introduce JavaScript into a Rails template A method update_city_state is defined as the :complete callback since two fields have to be changed with the response

16-14 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 16.3 The Controller The fill_city_state method is added to the controller to handle the asynchronous request The render method is used to create the content of the response since it is simple text