WEB 2.0 Programming with AJAX E.Soundararajan SIRD, IGCAR.

Slides:



Advertisements
Similar presentations
AJAX Compiled from “AJAX Programming” [Sang Shin]
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)
AJAX Presented by: Dickson Fu Dimas Ariawan Niels Andreassen Ryan Dial Jordan Nielson CMPUT 410 University of Alberta 2006.
1 JavaScript & AJAX CS , Spring JavaScript.
Chapter 6 DOJO TOOLKITS. Objectives Discuss XML DOM Discuss JSON Discuss Ajax Response in XML, HTML, JSON, and Other Data Type.
Web Design Basic Concepts.
The Document Object Model (DOM) & Asynchronous Javascript And XML (AJAX) : an introduction UFCEKG-20-2 : Data, Schemas and Applications.
What is Web Design?  Web design is the creation of a Web page using hypertext or hypermedia to be viewed on the World Wide Web.
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
Copyright © cs-tutorial.com. Introduction to Web Development In 1990 and 1991,Tim Berners-Lee created the World Wide Web at the European Laboratory for.
May 16 – 18, 2007 Copyright 2007, Data Access Worldwide May 16 – 18, 2007 Copyright 2007, Data Access Worldwide Build Great Web Application 'Fast and Easy'
CSCI 6962: Server-side Design and Programming Introduction to AJAX.
Lecture 12 – AJAX SFDV3011 – Advanced Web Development Reference: 1.
AJAX Without the “J” George Lawniczak. What is Ajax?
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.
Instructor, Dr. Khalili Bahram Jeevan Kumar Gogineni.
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.
1 Geospatial and Business Intelligence Jean-Sébastien Turcotte Executive VP San Francisco - April 2007 Streamlining web mapping applications.
AJAX (also known as: XMLHTTP, Remote Scripting, XMLHttpRequest, etc.) Matt Warden.
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,
AJAX محمد احمدی نیا 2 Of 27 What is AJAX?  AJAX = Asynchronous JavaScript and XML.  AJAX is not a new programming language, but.
AJAX Compiled from “AJAX Programming” [Sang Shin] (Asynchronous JavaScript and XML)
Asynchronous Javascript And XML AJAX : an introduction UFCEUS-20-2 : Web Programming.
Ajax ( Asynchronous JavaScript + XML ) Information Science and Knowledge Systems: Semantic Web Spring 2006 / Dr. Don Turnbull Presented by David Kim.
AJAX stands for Asynchronous JavaScript And XML. AJAX is a type of programming made popular in 2005 by Google (with Google Suggest). AJAX is not a new.
School of Computing and Information Systems CS 371 Web Application Programming AJAX.
CISC 3140 (CIS 20.2) Design & Implementation of Software Application II Instructor : M. Meyer Address: Course Page:
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
Weekend MS CS Program Internet and Web Technologies COT 5930 Web Project Development - Ajax Dr. Roy Levow, Associate Chair & Professor
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 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 AJAX Asynchronous JavaScript and XML --- MADHAVI
What is AJAX ? Asynchronous Javascript and XML. Not a stand-alone language or technology. It is a technique that combines a set of known technologies in.
AJAX – Asynchronous JavaScript And XML By Kranthi Kiran Nuthi CIS 764 Kansas State University.
INNOV-2: Build a Better Web Interface Using AJAX Chris Morgan Pandora Software Systems
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.
1 AJAX. AJAX – Whatzit? Asynchronous (content loading)‏ Javascript (logic & control)‏ And XML (request handling)‏
Ajax! Ajax Programming Ajax! Ajax Programming. Ajax! Ajax Programming Take a look at a typical desktop application (Spreadsheet app, etc.) The program.
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.
NCCUCS 軟體工程概論 Lecture 5: Ajax, Mashups April 29, 2014.
AJAX. Objectives Understand and apply AJAX Using AJAX in DOJO library.
Ajax SUBMITTED BY NITIN RAMANI C.S.E 3 rd Y 5 th S R.N CS SUBMITTED TO PRO. PUSHPARAJ PATEL SIR.
Open Solutions for a Changing World™ Eddy Kleinjan Copyright 2005, Data Access WordwideNew Techniques for Building Web Applications June 6-9, 2005 Key.
JavaScript and Ajax (Ajax Tutorial)
CSE 154 Lecture 11: AJAx.
Not a Language but a series of techniques
CS 371 Web Application Programming
AJAX and REST.
AJAX.
CSE 154 Lecture 11: AJAx.
CSE 154 Lecture 22: AJAX.
JavaScript & jQuery AJAX.
AJAX CS-422 Dick Steflik.
Intro to Ajax Fred Stluka Jan 25, 2006.
Presentation transcript:

WEB 2.0 Programming with AJAX E.Soundararajan SIRD, IGCAR

Web 2.0 Fly By Web 2.0 is really an “after-the-fact” catch-all for a collectively recognized phenomena the foaf project

Web 2.0 is the network as platform, spanning all connected devices; Web 2.0 applications are those that make the most of the intrinsic advantages of that platform: delivering software as a continually-updated service that gets better the more people use it, consuming and remixing data from multiple sources, including individual users, while providing their own data and services in a form that allows remixing by others, creating network effects through an "architecture of participation," and going beyond the page metaphor of Web 1.0 to deliver rich user experiences. Tim O'Reilly, “Web 2.0: Compact Definition?”Web 2.0: Compact Definition?

Lets continue looking...

Personalized User oriented Easy to Use Get you to the information you want Useful What Makes the Web 2.0 Different?

“Click, wait, and refresh” user interaction > Page refreshes from the server needed for all events, data submissions, and navigation > The user has to wait for the response Synchronous “request/response” communication model Browser always initiates the request Characteristics of Conventional Web Application

Slow response Loss of operation context during refresh Excessive server load and bandwidth consumption Lack of two-way, real-time communication capability for server initiated updates These are the reasons why Rich Internet Application (RIA) technologies were born. Issues of Conventional Web Application

Macromedia Flash Java Web Start DHTML DHTML with IFrame AJAX Rich Internet Application (RIA) Technologies

Designed for playing interactive movies Programmed with ActionScript Implementation examples > Macromedia Flex > Laszlo suite (open source) Pros: > Good for vector graphics Cons: > Browser needs a Flash plug-in > ActionScript is proprietary and hard to debug Macromedia Flash

Desktop application delivered over the net Pros > Desktop experience once loaded > Leverages Java technology to its fullest extent > Disconnected operation possible > Application can be digitally signed Cons > Old JRE-based system do not work Java Web Start

DHTML = JavaScript + DOM + CSS Used for creating interactive applications No asynchronous communication, however > Full page refresh still required DHTML (Dynamic HTML)

Introduction AJAX = Asynchronous JavaScript and XML AJAX = Asynchronous JavaScript and XML AJAX is not a new programming language, but a technique for creating better, faster, and more interactive web applications. AJAX is not a new programming language, but a technique for creating better, faster, and more interactive web applications. With AJAX, your JavaScript can communicate directly with the server, using the JavaScript XMLHttpRequest object. With this object, your JavaScript can trade data with a web server, without reloading the page. With AJAX, your JavaScript can communicate directly with the server, using the JavaScript XMLHttpRequest object. With this object, your JavaScript can trade data with a web server, without reloading the page. AJAX uses asynchronous data transfer (HTTP requests) between the browser and the web server, allowing web pages to request small bits of information from the server instead of whole pages. AJAX uses asynchronous data transfer (HTTP requests) between the browser and the web server, allowing web pages to request small bits of information from the server instead of whole pages. The AJAX technique makes Internet applications smaller, faster and more user-friendly. The AJAX technique makes Internet applications smaller, faster and more user-friendly.

About AJAX AJAX is Based on Web Standards AJAX is Based on Web Standards AJAX is based on the following web standards: AJAX is based on the following web standards: JavaScript JavaScript XML XML HTML HTML CSS CSS DOM DOM The web standards used in AJAX are well defined, and supported by all major browsers. AJAX applications are browser and platform independent. The web standards used in AJAX are well defined, and supported by all major browsers. AJAX applications are browser and platform independent.

DOM (Document Object Model) Object Oriented Representation for XML and HTML documents Object Oriented Representation for XML and HTML documents Based on Hierarchical (Tree) Structure Based on Hierarchical (Tree) Structure allows programs and scripts to build documents, navigate their structure, add, modify or delete elements and content allows programs and scripts to build documents, navigate their structure, add, modify or delete elements and content Provides a foundation for developing querying, filtering, transformation, rendering etc. applications on top of DOM implementations Provides a foundation for developing querying, filtering, transformation, rendering etc. applications on top of DOM implementations

CSS (Cascading Style Sheets) Set of Formatting rules that tell the browser how to present the document Set of Formatting rules that tell the browser how to present the document Helps to separate the content from the presentation Helps to separate the content from the presentation Reduce the download time by removing the formatting information from the document Reduce the download time by removing the formatting information from the document More control over formatting than HTML More control over formatting than HTML

So why is AJAX so hot—NOW? Demand for richer applications is growing Demand for richer applications is growing Broadband means we can—and want to—do more Broadband means we can—and want to—do more Recent Google applications have sparked people’s imagination Recent Google applications have sparked people’s imagination Google gmail, Google suggests, Google Maps Google gmail, Google suggests, Google Maps People are thinking of building APPLICATIONS…not just sites People are thinking of building APPLICATIONS…not just sites The Tipping Point The Tipping Point All of this has made rich internet apps reach its tipping point—where adoption spreads rapidly and dramatically All of this has made rich internet apps reach its tipping point—where adoption spreads rapidly and dramatically

Google maps > Goolgle Suggest > Gmail > ZUGGEST- an XMLHttp Experiment using Amazon > Real-Life Examples of AJAX apps

AJAX Basics AJAX Uses HTTP Requests AJAX Uses HTTP Requests With AJAX, your JavaScript communicates directly with the server, through the JavaScript XMLHttpRequest object With AJAX, your JavaScript communicates directly with the server, through the JavaScript XMLHttpRequest object With an HTTP request, a web page can make a request to, and get a response from a web server - without reloading the page. The user will stay on the same page, and he or she will not notice that scripts request pages, or send data to a server in the background. With an HTTP request, a web page can make a request to, and get a response from a web server - without reloading the page. The user will stay on the same page, and he or she will not notice that scripts request pages, or send data to a server in the background.

AJAX Basics The XMLHttpRequest Object The XMLHttpRequest Object By using the XMLHttpRequest object, a web developer can update a page with data from the server after the page has loaded! By using the XMLHttpRequest object, a web developer can update a page with data from the server after the page has loaded! AJAX was made popular in 2005 by Google (with Google Suggest). AJAX was made popular in 2005 by Google (with Google Suggest). Google Suggest is using the XMLHttpRequest object to create a very dynamic web interface: When you start typing in Google's search box, a JavaScript sends the letters off to a server and the server returns a list of suggestions. Google Suggest is using the XMLHttpRequest object to create a very dynamic web interface: When you start typing in Google's search box, a JavaScript sends the letters off to a server and the server returns a list of suggestions. Google Suggest Google Suggest The XMLHttpRequest object is supported in Internet Explorer 5.0+, Safari 1.2, Mozilla 1.0 / Firefox, Opera 8+, and Netscape 7. The XMLHttpRequest object is supported in Internet Explorer 5.0+, Safari 1.2, Mozilla 1.0 / Firefox, Opera 8+, and Netscape 7.

A New Way of Building Applications AJAX Applications Are: AJAX Applications Are: 3-tier client/server apps 3-tier client/server apps Browser ↔ App Server ↔ Data Source Browser ↔ App Server ↔ Data Source Event driven Event driven User clicks, user drags, user changes data User clicks, user drags, user changes data Graphics Intensive Graphics Intensive Visual Effects, Rich Visual Controls Visual Effects, Rich Visual Controls Are Data Oriented Are Data Oriented Users are manipulating and entering data Users are manipulating and entering data Are Complex Are Complex Pages hold many more controls and data than page- oriented applications Pages hold many more controls and data than page- oriented applications Multiple Master-Detail Relationships in one page Multiple Master-Detail Relationships in one page

AJAX will change web development AJAX represents a fundamental shift in how web applications are built We’ll be building 3-Tier Client/Server applications with AJAX Users want enhanced, interactive functionality Users want enhanced, interactive functionality They want their data easily accessible and maintainable They want their data easily accessible and maintainable They don’t want screen flicker They don’t want screen flicker They don’t want over-the-top GUI—just functional They don’t want over-the-top GUI—just functional Once they see an AJAX application—they want it now Once they see an AJAX application—they want it now

Two ways of talking to the server… XMLHTTPRequest object XMLHTTPRequest object Allows for asynchronous GETs + POSTs to the server Allows for asynchronous GETs + POSTs to the server Does not show the user anything—no status messages Does not show the user anything—no status messages Can have multiple XMLHTTPRequest active at one time Can have multiple XMLHTTPRequest active at one time Allows you to specify a handler method for state changes Allows you to specify a handler method for state changes Handler notified when request is: Handler notified when request is: Initialized Initialized Started Started In the process of being returned In the process of being returned Completely finished Completely finished Originally only available for Microsoft IE Originally only available for Microsoft IE

XMLHttpRequest Object: Methods open(“method”, “URL”) open(“method”, “URL”) open(“method”, “URL”, async, username, password) open(“method”, “URL”, async, username, password) Assigns destination URL, method, etc. Assigns destination URL, method, etc. send(content) send(content) Sends request including postable string or DOM object data Sends request including postable string or DOM object data abort() abort() Terminates current request Terminates current request getAllResponseHeaders() getAllResponseHeaders() Returns headers (labels + values) as a string Returns headers (labels + values) as a string getResponseHeader(“header”) getResponseHeader(“header”) Returns value of a given header Returns value of a given header setRequestHeader(“label”,”value”) setRequestHeader(“label”,”value”) Sets Request Headers before sending Sets Request Headers before sending

Security Issues You can only hit the domain that the original web page came from You can only hit the domain that the original web page came from Because of this, the AJAX technique cannot normally be used to access a Web Service of a 3 rd party server Because of this, the AJAX technique cannot normally be used to access a Web Service of a 3 rd party server You can wrap those requests through your own server You can wrap those requests through your own server You can allow XMLHTTPRequest to access specific sites in your browser security settings You can allow XMLHTTPRequest to access specific sites in your browser security settings IFRAME can be used to access any site if needed IFRAME can be used to access any site if needed

Wow..I didn’t know soccer teams did web programming..

AJAX Patterns Change Browser Content with the DOM Change Browser Content with the DOM Return HTML or XML and change named items Return HTML or XML and change named items Usually DIVs or SPANs Usually DIVs or SPANs Remote Scripting Remote Scripting Execute business functions on the server from the client Execute business functions on the server from the client Events & Scheduling Events & Scheduling Using Timers to ping server on regular basis Using Timers to ping server on regular basis Specialized Functions to perform common GUI tasks Specialized Functions to perform common GUI tasks Populate SELECT list Populate SELECT list Pass target DIV to replace to the server Pass target DIV to replace to the server Instant Validation as User Works Instant Validation as User Works SAVE instead of SUBMIT SAVE instead of SUBMIT CANCEL instead of BACK CANCEL instead of BACK DHTML Techniques DHTML Techniques CSS, Drag & Drop CSS, Drag & Drop Server-Side Code Generation Server-Side Code Generation Return Javascript to client Return Javascript to client

AJAX Frameworks Pure JavaScript Framework Pure JavaScript Framework Infrastructure Infrastructure Provides basic piping & portable browser abstractions Provides basic piping & portable browser abstractions Content up to developer Content up to developer Typical Functionality: Typical Functionality: Wrapper around XMLHttpRequest Wrapper around XMLHttpRequest XML manipulation & interrogation XML manipulation & interrogation DOM manipulations based on responses from XMLHttpRequest DOM manipulations based on responses from XMLHttpRequest Application Framework Application Framework Includes basic Infrastruture functionality Includes basic Infrastruture functionality Server-Side Framework Server-Side Framework HTML/JavaScript Generation HTML/JavaScript Generation Server provides complete HTML/JS code generation and browser  server coordination Server provides complete HTML/JS code generation and browser  server coordination Browser-side coding is for customization Browser-side coding is for customization Remote Invocation Remote Invocation JavaScript calls routed directly to server-side functions (Java Methods) and returned back to Javascript callback handlers JavaScript calls routed directly to server-side functions (Java Methods) and returned back to Javascript callback handlers

Pure JavaScript Pure JavaScript DOJO (9/04) DOJO (9/04) Prototype (2001) Prototype (2001) Open Rico (5/05) Open Rico (5/05) Qooxdoo (5/05) Qooxdoo (5/05) Pure JavaScript Infrastructural Pure JavaScript Infrastructural AjaxJS (5/05) AjaxJS (5/05) HTMLHttpRequest (2001) HTMLHttpRequest (2001) Interactive Website Framework (5/05) Interactive Website Framework (5/05) LibXMLHttpRequest (6/03) LibXMLHttpRequest (6/03) RSLite RSLite Sack (5/05) Sack (5/05) Sarissa (2/03) Sarissa (2/03) XHConn (4/05) XHConn (4/05) Server-Side (Multi Language) Server-Side (Multi Language) Cross-Platform Asynchronous Interface Toolkit (5/05) Cross-Platform Asynchronous Interface Toolkit (5/05) SAJAX (3/05) SAJAX (3/05) Javascript Object Notation (JSON) & JSON-RPC Javascript Object Notation (JSON) & JSON-RPC Javascript Remote Scripting (2000) Javascript Remote Scripting (2000) Server-Side (Java) Server-Side (Java) Echo2 (3/05) Echo2 (3/05) Direct Web Remoting (DWR) (2005)] Direct Web Remoting (DWR) (2005)] ThinkCAP Minerva (04/2005) ThinkCAP Minerva (04/2005) Server-Side (Lisp) Server-Side (Lisp) CL-Ajax CL-Ajax Server-Side (.NET) Server-Side (.NET) Ajax.NET (305) Ajax.NET (305) Server-Side (PHP) Server-Side (PHP) AjaxAC (4/05) AjaxAC (4/05) JPSpan JPSpan XAJAX XAJAX Server-Side (Ruby) Server-Side (Ruby) Ruby-On-Rails (3/05) Ruby-On-Rails (3/05) Pick a Framework… any Framework

Common Widgets Form Validation Form Validation Interactive Grids Interactive Grids Drilldowns TreeViews Drilldowns TreeViews Auto Completion Auto Completion Application Status Area Application Status Area Progress Bars Progress Bars Dynamic Lists Dynamic Lists Tabs Tabs AJAX’ed Portlets AJAX’ed Portlets Predictive Fetch Predictive Fetch

Sites of Interest Foundational Libraries Foundational Libraries Prototype Prototype script.acul.us script.acul.us very OO foundation to manipulate XMLHTTPRequest very OO foundation to manipulate XMLHTTPRequest lots of visual effects, autocomplete, sliders, controls lots of visual effects, autocomplete, sliders, controls Core of “Ruby on Rails” AJAX implementation Core of “Ruby on Rails” AJAX implementation OpenRico OpenRico Builds on Prototype, adds some controls Builds on Prototype, adds some controls Accordion, Live Grid Accordion, Live Grid Sarissa Sarissa Heavy duty XML library for XSLT Heavy duty XML library for XSLT SAJAX & XAJAX SAJAX & XAJAX PHP libraries with some good ideas PHP libraries with some good ideas Server driven JS creation Server driven JS creation

Basic AJAX Process JavaScript – Define an object for sending HTTP requests – Initiate request Get request object Designate a request handler function – Supply as onreadystatechange attribute of request Initiate a GET or POST request Send data – Handle response Wait for readyState of 4 and HTTP status of 200 Extract return text with responseText or responseXML Do something with result HTML – Loads JavaScript – Designates control that initiates request – Gives ids to input elements that will be read by script

Define Object var request; function getRequestObject() { if (window.ActiveXObject) { return(new ActiveXObject("Microsoft.XMLHTTP")); } else if (window.XMLHttpRequest) { return(new XMLHttpRequest()); } else { return(null);}}

Initiate Request function sendRequest() { request = getRequestObject(); request.onreadystatechange = handleResponse; request.open("GET", "message-data.html", true); request.send(null);}

Handling Response function handleResponse() { if (request.readyState == 4) { alert(request.responseText);}}

HTML Code <!DOCTYPE html PUBLIC "..." " Ajax: Simple Message Ajax: Simple Message <script src="mesg.js" type="text/javascript"></script></head><body><center> Ajax: Simple Message Ajax: Simple Message </table><p/> <input type="button" value="Show Message" onclick="sendRequest()"/></form></center></body></html>

AJAX DB Example AJAX DB Example

HTML File <html><head> </head><body><form> Select a State: Tamilnadu Tamilnadu Kerala Kerala Karnataka Karnataka</select></form><p> City Names will be listed here. City Names will be listed here. </p></body></html> Java Script File JavaScript Function Call

var xmlHttp function showCityname(str) {xmlHttp=GetXmlHttpObject(); if (xmlHttp==null) { alert ("Your browser does not support AJAX!"); alert ("Your browser does not support AJAX!"); return; return; } var url=" url=url+"?q="+str;url=url+"&sid="+Math.random();xmlHttp.onreadystatechange=stateChanged;xmlHttp.open("GET",url,true);xmlHttp.send(null);} Java Script File – Show Cityname() Function

AJAX - Sending a Request to the Server To send off a request to the server, we use the open() method and the send() method. To send off a request to the server, we use the open() method and the send() method. The open() method takes three arguments. The first argument defines which method to use when sending the request (GET or POST). The second argument specifies the URL of the server-side script. The third argument specifies that the request should be handled asynchronously. The send() method sends the request off to the server. If we assume that the HTML and PHP file are in the same directory, the code would be: The open() method takes three arguments. The first argument defines which method to use when sending the request (GET or POST). The second argument specifies the URL of the server-side script. The third argument specifies that the request should be handled asynchronously. The send() method sends the request off to the server. If we assume that the HTML and PHP file are in the same directory, the code would be: xmlHttp.open("GET",“getname.php",true); xmlHttp.send(null); xmlHttp.open("GET",“getname.php",true); xmlHttp.send(null);

Defines the url (filename) to send to the server Defines the url (filename) to send to the server Adds a parameter (q) to the url with the content of the input field Adds a parameter (q) to the url with the content of the input field Adds a random number to prevent the server from using a cached file Adds a random number to prevent the server from using a cached file Creates an XMLHTTP object, and tells the object to execute a function called stateChanged when a change is triggered Creates an XMLHTTP object, and tells the object to execute a function called stateChanged when a change is triggered Opens the XMLHTTP object with the given url. Opens the XMLHTTP object with the given url. Sends an HTTP request to the server Sends an HTTP request to the server

Javascript- State Changed function stateChanged() { if (xmlHttp.readyState==4) { document.getElementById("txtHint").innerHTML=xmlHttp.re sponseText; document.getElementById("txtHint").innerHTML=xmlHttp.re sponseText;}}

State changed Function The readyState property holds the status of the server's response. Each time the readyState changes, the onreadystatechange function will be executed. The readyState property holds the status of the server's response. Each time the readyState changes, the onreadystatechange function will be executed. Request is not initialized -0 Request is not initialized -0 The request has been set up – 1 The request has been set up – 1 The request has been sent - 2 The request has been sent - 2 The request is in process – 3 The request is in process – 3 The request is complete - 4 The request is complete - 4

function GetXmlHttpObject() { var xmlHttp=null; try { // Firefox, Opera 8.0+, Safari // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer // Internet Explorer try try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } JavaScript – Define XmlHttpObject

XMLHttpRequest Properties onreadystatechange onreadystatechange Event handler that fires at each state change Event handler that fires at each state change You implement your own function that handles this You implement your own function that handles this readyState – current status of request readyState – current status of request 0 = uninitialized 0 = uninitialized 1 = loading 1 = loading 2 = loaded 2 = loaded 3 = interactive (some data has been returned) 3 = interactive (some data has been returned) This is broken in IE right now This is broken in IE right now 4 = complete 4 = complete status status HTTP Status returned from server: 200 = OK HTTP Status returned from server: 200 = OK responseText responseText String version of data returned from server String version of data returned from server responseXML responseXML XML DOM document of data returned XML DOM document of data returned statusText statusText Status text returned from server Status text returned from server

<?php header("Cache-Control: no-cache, must-revalidate"); // Date in the past // Date in the past header("Expires: Mon, 26 Jul :00:00 GMT"); $q=$_GET["q"];//lookup all hints from array if length of q>0 $query = " select city from city where state = '$q' "; $mysql_link=mysql_connect(" ","guest","");mysql_select_db("test",$mysql_link); $mysql_result = mysql_query($query, $mysql_link); $response= " "; while ( $row = mysql_fetch_row($mysql_result)) { $city = $row[0]; { $city = $row[0]; $response.=" ".$city." "; $response.=" ".$city." "; }$response.="</table>"; echo $response; ?> PHP Code – Server Script

– Dojo. Open source JavaScript toolkit with Ajax support – Google Web Toolkit Write code in Java, translate it to JavaScript – script.aculo.us Free JavaScript toolkit with Ajax support – Yahoo User Interface Library (YUI) Free JavaScript toolkit with some Ajax support Client-Side Tools

– Direct Web Remoting Lets you call Java methods semi-directly from JavaScript – JSON/JSON-RPC For sending data to/from JavaScript with less parsing – JSP custom tag libraries Create tags that generate into HTML and JavaScript 84 J2EE training: Server-Side Tools

Questions? Questions?