Chengyu Sun California State University, Los Angeles

Slides:



Advertisements
Similar presentations
Dodick Zulaimi Sudirman Lecture 12 Introduction to AJAX Pengantar Teknologi Internet Introduction to Internet Technology.
Advertisements

9. AJAX & RIA. 2 Motto: O! call back yesterday, bid time return. — William Shakespeare.
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,
Does Ajax suck? CS575 Spring 2007 Chanwit Suebsureekul.
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.
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
CSCI 6962: Server-side Design and Programming Introduction to AJAX.
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.
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.
Client side web programming Introduction Jaana Holvikivi, DSc. School of ICT.
CS320 Web and Internet Programming Handling HTTP Requests Chengyu Sun California State University, Los Angeles.
Random Logic l Forum.NET l AJAX Behind the buzz word Forum.NET ● January 23, 2006.
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.
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.
A New Way To Web Applications Development Tin Htut Htut Naing Oo Myanmar Information Technology.
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.
CS520 Web Programming Introduction to Ajax and jQuery Chengyu Sun California State University, Los Angeles.
CS320 Web and Internet Programming Handling HTTP Requests 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.
Data Virtualization Tutorial… CORS and CIS
AJAX and REST.
XMLHttp Object.
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.
CS3220 Web and Internet Programming Handling HTTP Requests
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
Chengyu Sun California State University, Los Angeles
CS3220 Web and Internet Programming JavaScript Basics
Communicating with the Server
Presentation transcript:

Chengyu Sun California State University, Los Angeles CS3220 Web and Internet 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 Servlet Number 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 Then Mozilla added it to Firefox Then it was used to create 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 XMLHttpRequest is the name of the JavaScript object; the actual request is still an HTTP Request, i.e. there is no difference on the server side.

Problems of Plain JavaScript + XMLHttpRequest Each browser has their own JavaScript implementation Code that works on some browsers may not work on others 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

Example: AJAX GuestBook My Guest Book John says: Hello! Delete Jane says: Your website looks nice. Delete Joe says: Nice to meet you. I’m from China. Delete Add Implement Add and Delete Entry using AJAX

About The Example User-defined attributes in HTML 5: data-* Getting auto-generated IDs in JDBC Statement.RETURN_GENERATED_KEYS Statement executeUpdate(sql, returnGeneratedKeys) getGeneratedKeys() PreparedStatement connection.prepareStatement(sql, returnGeneratedKeys) Return an empty response