AJAX. Lab. de Bases de Dados e Aplicações Web MIEIC, FEUP 2010/11. Sérgio Nunes

Similar documents
ASP.NET AJAX adds Asynchronous JavaScript and XML. ASP.NET AJAX was up until the fall of 2006 was known by the code-known of Atlas.

XMLHttpRequest. CS144: Web Applications

AJAX. Lecture 26. Robb T. Koether. Fri, Mar 21, Hampden-Sydney College. Robb T. Koether (Hampden-Sydney College) AJAX Fri, Mar 21, / 16

So, if you receive data from a server, in JSON format, you can use it like any other JavaScript object.

AJAX and PHP AJAX. Christian Wenz,

JSON is a light-weight alternative to XML for data-interchange JSON = JavaScript Object Notation

AJAX ASYNCHRONOUS JAVASCRIPT AND XML. Laura Farinetti - DAUIN

AJAX. Ajax: Asynchronous JavaScript and XML *

User Interaction: jquery

AJAX: Asynchronous Event Handling Sunnie Chung

REST. Web-based APIs

JSON as an XML Alternative. JSON is a light-weight alternative to XML for datainterchange

AJAX: Rich Internet Applications

What the Bayeux? Filip Hanik. SpringSource Inc Keystone, Colorado, Slide 1

AJAX. Introduction. AJAX: Asynchronous JavaScript and XML

TIME SCHEDULE MODULE TOPICS PERIODS. HTML Document Object Model (DOM) and javascript Object Notation (JSON)

Kyle Rainville Littleton Coin Company

AJAX: Introduction CISC 282 November 27, 2018

RKN 2015 Application Layer Short Summary

Working with Javascript Building Responsive Library apps

Jquery.ajax Call Returns Status Code Of 200 But Fires Jquery Error

Introduction Haim Michael. All Rights Reserved.

Web 2.0 and Security


Multimedia im Netz Online Multimedia Winter semester 2015/16. Tutorial 07 Minor Subject

,

Introduction to Web Services

Web Application Security

Module 5 JavaScript, AJAX, and jquery. Module 5. Module 5 Contains 2 components

The course also includes an overview of some of the most popular frameworks that you will most likely encounter in your real work environments.

Developing Ajax Web Apps with GWT. Session I

JavaScript Specialist v2.0 Exam 1D0-735

HTTP Communication on Tizen

Create-A-Page Design Documentation

Programming for Digital Media. Lecture 7 JavaScript By: A. Mousavi and P. Broomhead SERG, School of Engineering Design, Brunel University, UK

AJAX Programming Chris Seddon

REST AND AJAX. Introduction. Module 13

Ajax. Ronald J. Glotzbach

AJAX: From the Client-side with JavaScript, Back to the Server

Module7: AJAX. Click, wait, and refresh user interaction. Synchronous request/response communication model. Page-driven: Workflow is based on pages

COURSE OUTLINE MOC 20480: PROGRAMMING IN HTML5 WITH JAVASCRIPT AND CSS3

AJAX: The Basics CISC 282 March 25, 2014

Fall Semester (081) Module7: AJAX

AJAX Programming Overview. Introduction. Overview

Jquery Ajax Json Php Mysql Data Entry Example

Outline. AJAX for Libraries. Jason A. Clark Head of Digital Access and Web Services Montana State University Libraries

AJAX(Asynchronous Javascript + XML) Creating client-side dynamic Web pages

Copyright Descriptor Systems, Course materials may not be reproduced in whole or in part without prior written consent of Joel Barnum

CSE 130 Programming Language Principles & Paradigms Lecture # 20. Chapter 13 Concurrency. + AJAX Discussion

WebApp development. Outline. Web app structure. HTML basics. 1. Fundamentals of a web app / website. Tiberiu Vilcu

Session 18. jquery - Ajax. Reference. Tutorials. jquery Methods. Session 18 jquery and Ajax 10/31/ Robert Kelly,

Procedure to request a JSON file or an XML file in the local host Using AJAX with JQuery

/ Introduction to XML

AJAX: The Basics CISC 282 November 22, 2017

AJAX Workshop. Karen A. Coombs University of Houston Libraries Jason A. Clark Montana State University Libraries

Programming in HTML5 with JavaScript and CSS3

Lesson 12: JavaScript and AJAX

Networking & The Web. HCID 520 User Interface Software & Technology


Contents. Demos folder: Demos\14-Ajax. 1. Overview of Ajax. 2. Using Ajax directly. 3. jquery and Ajax. 4. Consuming RESTful services

IN Development in Platform Ecosystems Lecture 3: json, ajax, APIs

Phase I. Initialization. Research. Code Review. Troubleshooting. Login.aspx. M3THOD, LLC Project Documentation

Chapter 3: Web Paradigms and Interactivity

COURSE 20480B: PROGRAMMING IN HTML5 WITH JAVASCRIPT AND CSS3

Web Programming/Scripting: PHP and AJAX Refresher

Module 5 JavaScript, AJAX, and jquery. Module 5. Module 5 Contains an Individual and Group component

Using JavaScript on Client and Server with Project Phobos

Programming in HTML5 with JavaScript and CSS3

Etanova Enterprise Solutions

2/6/2012. Rich Internet Applications. What is Ajax? Defining AJAX. Asynchronous JavaScript and XML Term coined in 2005 by Jesse James Garrett

Assignment: Seminole Movie Connection

Programming in HTML5 with JavaScript and CSS3

Term Paper. P r o f. D r. E d u a r d H e i n d l. H o c h s c h u l e F u r t w a n g e n U n i v e r s i t y. P r e s e n t e d T o :

Ajax HTML5 Cookies. Sessions 1A and 1B

Web 2.0 Käyttöliittymätekniikat

Controller/server communication

A.A. 2008/09. What is Ajax?

20480B: Programming in HTML5 with JavaScript and CSS3

Part of this connection identifies how the response can / should be provided to the client code via the use of a callback routine.

Abstract. 1. Introduction. 2. AJAX overview

Session 11. Ajax. Reading & Reference

Microsoft Programming in HTML5 with JavaScript and CSS3

Course 20480: Programming in HTML5 with JavaScript and CSS3

XML JavaScript Object Notation JSON Cookies Miscellaneous What Javascript can t do. OOP Concepts of JS

GRITS AJAX & GWT. Trey Roby. GRITS 5/14/09 Roby - 1

Licence CRRW IUT de Marne-la-Vallée 26/01/2018. AJAX with jquery. Philippe Gambette

COMET, HTML5 WEBSOCKETS OVERVIEW OF WEB BASED SERVER PUSH TECHNOLOGIES. Comet HTML5 WebSockets. Peter R. Egli INDIGOO.COM. indigoo.com. 1/18 Rev. 2.

Web Application with AJAX. Kateb, Faris; Ahmed, Mohammed; Alzahrani, Omar. University of Colorado, Colorado Springs

CITS1231 Web Technologies. Ajax and Web 2.0 Turning clunky website into interactive mashups

Copyright is owned by the Author of the thesis. Permission is given for a copy to be downloaded by an individual for the purpose of research and

Oracle WebLogic Portal

Tooling for Ajax-Based Development. Craig R. McClanahan Senior Staff Engineer Sun Microsystems, Inc.

Networking & The Web. HCID 520 User Interface Software & Technology

16. Objects & JSON. Dr. Dave Parker. Informa;on and the Web, 2014/15

Controller/server communication

Use of PHP for DB Connection. Middle and Information Tier

Introduction to Web Application Development Using JEE, Frameworks, Web Services and AJAX

IERG 4080 Building Scalable Internet-based Services

Client Side JavaScript and AJAX

The University of Bradford Institutional Repository

Transcription:

AJAX Lab. de Bases de Dados e Aplicações Web MIEIC, FEUP 2010/11 Sérgio Nunes

Server calls from web pages using JavaScript call HTTP data

Motivation The traditional request-response cycle in web applications is synchronous. With AJAX we can have asynchronous interactions, resulting in a much richer user experience. Principal motivation for AJAX use is the improved user experience in web applications. Make web applications more similar to desktop applications.

Brief History In 1999 Microsoft introduced the XMLHTTP feature in IE 5. Later adopted by other browser as the XMLHttpRequest JavaScript object. First web applications incorporating background HTTP requests date back to 2000. Wider visibility and adoption happened after GMail (2004) and Google Maps (2005). The term AJAX was coined in 2005.

AJAX AJAX stands for Asynchronous JavaScript and XML. AJAX is a group of technologies combined to implement background calls in web applications. A browser technology independent of server software. Many libraries and toolkits are available to abstract low-level details (e.g. jquery, Prototype, Dojo, etc). Typical use cases: form validation (e.g. mandatory fields), simple interactions (e.g. likes), input field suggestions.

Traditional Web App Client Server html request waiting processing html html request waiting processing html html User needs to wait for server response.

AJAX Web App Client Server background request processing xml data html background request processing xml data User interaction is independent of server access.

XMLHttpRequest object JavaScript object that can handle communication between clients and servers. The XMLHttpRequest object is created by the client. Browser JavaScript XMLHttpRequest 2. HTTP request 3. HTTP response Server 1. Event Generated 4. Update Document Web Page

XMLHttpRequest Example var xmlhttp = new XMLHttpRequest(); Create XMLHttpRequest object. Not so simple in real world applications. Older browser versions need to be supported. xmlhttp.open("get", "api/seach.php", true); xmlhttp.onreadystatechange = handleresponse; Make asynchronous call, limited to same domain. Define function to handle response. function handlerequest() { if (xmlhttp.readystate == 4) { // ok... } else { // not ok... } } Check response code. Response body is available in xmlhttp.responsexml.

JSON JSON stands for JavaScript Object Notation. A simple text-based, lightweight data interchange format that is easy to generate and easy to parse. Smaller footprint than XML, thus higher transmission speeds. <person> <firstname>john</firstname> <lastname>smith</lastname> <age>25</age> </person> { } "firstname": "John", "lastname": "Smith", "age": 25 XML JSON

JSON Examples { } "firstname": "John" Object with one member. var["firstname"] // John { } "firstname": "John", "lastname": "Smith" Object with two members. var["lastname"] // Smith { } "firstname": "John", "tags": ["a", "b", 1] Object with array as value. var["tags"][0] // a { } "firstname": "John", "address": { } "street": "Sesame", "city": "NYC" Object with objects. var["address"]["street"] // Sesame

AJAX with jquery jquery.ajax( url, [ settings ] ) url URL to which the request is sent. settings key/value pairs that configure the AJAX request - async: if false, the request is made synchronously. - data: data to be sent to the server, as key/value pair. - type: the type of HTTP request to be made (e.g. POST/GET). - cache: if false will force the browser not to use cache. - success: a function to be called on success....

$.ajax({ type: "GET", url: "test.js", datatype: "script" }); Load and execute a JavaScript file.

$.ajax({ type: "POST", url: "some.php", data: "name=john&location=boston", success: function(msg){ alert( "Data Saved: " + msg ); } }); Save data to server and notify user when complete.

$.ajax({ url: "test.html", cache: false, success: function(html){ $("#results").append(html); } }); Retrieve the latest version of an HTML page.

Parsing JSON jquery.parsejson( json ) Takes a well-formed JSON string and returns the resulting JavaScript object. var obj = jquery.parsejson('{"name":"john"}'); alert( obj.name === "John" );

AJAX Drawbacks Pages dynamically created using AJAX requests are not available in the browser's history. Dynamic web page updates make it difficult to bookmark particular state of an application. Dynamically created web pages are inaccessible to web crawlers, given that they require JavaScript execution. Reduced accessibility to clients not supporting JavaScript. Also limited support in screen-readers. May lead to complex code, harder to maintain or debug.

Notes Use JSONP for cross-domain calls. AJAX is a presentation layer technique. Avoid moving business logic into the presentation layer. Web applications should work with AJAX disabled - worse user experience but still functional. Graceful degradation!

Related Concepts The HTML5 WebSocket API enables web pages to establish two-way communication with a remote host. AJAX enables browsers to pull information from web servers. COMET is way to enable web servers to push information to browsers. Avoids repeated pulls while waiting for information.

References Ajax: A New Approach to Web Applications (2005) http://www.adaptivepath.com/ideas/e000385 jquery API - jquery.ajax() http://api.jquery.com/jquery.ajax/