Chengyu Sun California State University, Los Angeles

Slides:



Advertisements
Similar presentations
9. AJAX & RIA. 2 Motto: O! call back yesterday, bid time return. — William Shakespeare.
Advertisements

Asynchronous HTTP request generation in JavaScript (AJAX)
19-Jun-15 Ajax. The hype Ajax (sometimes capitalized as AJAX) stands for Asynchronous JavaScript And XML Ajax is a technique for creating “better, faster,
Chapter 6 DOJO TOOLKITS. Objectives Discuss XML DOM Discuss JSON Discuss Ajax Response in XML, HTML, JSON, and Other Data Type.
The Document Object Model (DOM) & Asynchronous Javascript And XML (AJAX) : an introduction UFCEKG-20-2 : Data, Schemas and Applications.
Interactive Web Application with AJAX
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.
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
CSCI 6962: Server-side Design and Programming Introduction to AJAX.
Lecture 12 – AJAX SFDV3011 – Advanced Web Development Reference: 1.
Ajax - Part II Communicating with the Server. Learning Objectives By the end of this lecture, you should be able to: – Describe the overview of steps.
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.
Posting XML Data From the Client to a Server Eugenia Fernandez IUPUI.
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:
06/10/2015AJAX 1. 2 Introduction All material from AJAX – what is it? Traditional web pages and operation Examples of AJAX use Creating.
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)
Ajax. –Asynchronous JavaScript and XML –Umbrella term for technologies that often: Use client-side scripting for layout and formatting Use less than full.
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.
Ajax for Dynamic Web Development Gregory McChesney.
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.
SE-2840 Dr. Mark L. Hornick 1 Introduction to Ajax Asynchronous Javascript And XML.
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.
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.
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)‏
ASP.Net ICallback Vijayalakshmi G M Senior Trainer Binary Spectrum.
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.
How to consume a RESTful service using jQuery. Introduction  In this post we see how to consume the RESTful service described in the post Design a RESTful.
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.
CS520 Web Programming Introduction to Ajax and jQuery Chengyu Sun California State University, Los Angeles.
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)
CSE 154 Lecture 11: AJAx.
Understanding XMLHttpRequest
Not a Language but a series of techniques
AJAX AJAX = Asynchronous JavaScript and XML.
AJAX and REST.
XMLHttp Object.
AJAX.
AJAX.
CSE 154 Lecture 11: AJAx.
CSE 154 Lecture 22: AJAX.
AJAX Robin Burke ECT 360.
JavaScript & AJAX.
ISC440: Web Programming 2 AJAX
JavaScript & jQuery AJAX.
Chengyu Sun California State University, Los Angeles
AJAX CS-422 Dick Steflik.
Intro to Ajax Fred Stluka Jan 25, 2006.
DR. JOHN ABRAHAM PROFESSOR UTPA
Chengyu Sun California State University, Los Angeles
CS3220 Web and Internet Programming JavaScript Basics
Chengyu Sun California State University, Los Angeles
Communicating with the Server
Presentation transcript:

Chengyu Sun California State University, Los Angeles CS5220 Advanced Topics in Web Programming Asynchronous JavaScript and XML (AJAX) Chengyu Sun California State University, Los Angeles

Improve Responsiveness of Web Applications Improve user experience Interactive Responsive Reduce server workload Handle input events Implement as much functionality on the client-side as possible Hide the inevitable communication overhead from the user

Communicate with Server The synchronous request-response model is still a limiting factor in responsiveness Solution: XMLHttpRequest A JavaScript object Send request and receive response in JavaScript Response can be handled asynchronously Do not need to wait for the response

Understand Asynchronous … send( request ); // wait for response process( response ); // do other things … send( request ); // don’t wait for response process( response ); // do other things … What’s the problem?? What’s the solution??

… Understand Asynchronous // callback function function foo( response ) { process( response ); } // set a callback function // which will be called // when the response comes // back … … send( request ); // do other things … Same as handling events like click event in GUI programming.

An XMLHttpRequest Example number1.html A client scripts sends an XMLHttpRequest A server program responds with a random number When the message arrives on the client, a callback function is invoked to update the document

About the Example clickHandler() newXMLHttpRequest() updateDocument() getReadyStateHandler()

XMLHttpRequest - Properties onreadystatechange readyState 0 – uninitialized 1 – loading 2 – loaded 3 – interactive 4 – complete status statusText responseBody responseStream responseText responseXML

XMLHttpRequest - Methods abort() getAllResponseHeaders() getResponseHeader( header ) open( method, url, asyncFlag, username, password ) asyncFlag, username, password are optional send( messageBody ) setRequestHeader( name, value )

So What is AJAX? Asynchronous JavaScript and XML http://adaptivepath.org/ideas/ajax-new-approach-web-applications/ JavaScript + XMLHttpRequest Characteristics of AJAX Non-blocking – the server response is handled asynchronously with a callback function Partial page update using JavaScript

More About AJAX XMLHttpRequest used to be an IE specific feature that received little attention It’s all started by Google Maps The beginning of “Web 2.0”

Key Elements of an AJAX Operation Client Server Event Event handler Create a XMLHttpRequest Attach a callback function Send the request Callback function Process the response Update the HTML Page Process the request Send back a response

Problems of Plain JavaScript + XMLHttpRequest Each browser has their own JavaScript implementation Code that works on some browsers may not work on others Lack of pre-made GUI components Implementing AJAX operations is quite tedious

jQuery To The Rescue number2.html http://api.jquery.com/category/ajax/ $.ajax() URL can be specified as an argument or as a field of the settings object success callback function will be called if the request is successful (i.e. response status code 200)

More About settings Data Fields Callback Functions method data processData contentType dataType context success error complete statusCode

Send Data to Server data is an object in most cases, and by default jQuery encodes data into a query string To send data in other format Set processData to false Set the appropriate contentType, e.g. application/json Encode the data, e.g. JSON.stringify(obj)

Receive Data from Server jQuery can usually guess the correct data format for the response dataType explicitly specifies the response data format dataType also sets Accept header

More AJAX Examples: CRUD jQuery UI – http://jqueryui.com/ User Management View Delete Add Edit