What is AJAX? Ajax. Traditional Client-Server Interaction. What is Ajax? (cont.) Ajax Client-Server Interaction. What is Ajax? (cont.



Similar documents
Web Programming Step by Step

JavaScript: Client-Side Scripting. Chapter 6

Client-side Web Engineering From HTML to AJAX

It is highly recommended that you are familiar with HTML and JavaScript before attempting this tutorial.

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 :

An introduction to creating Web 2.0 applications in Rational Application Developer Version 8.0

Performance Testing for Ajax Applications

Software Requirements Specification For Real Estate Web Site

Credits: Some of the slides are based on material adapted from

XML Processing and Web Services. Chapter 17

Tutorial básico del método AJAX con PHP y MySQL

4 Understanding. Web Applications IN THIS CHAPTER. 4.1 Understand Web page development. 4.2 Understand Microsoft ASP.NET Web application development

Example for Using the PrestaShop Web Service : CRUD

Core Ideas CHAPTER 1 PART. CHAPTER 2 Pre-Ajax JavaScript Communications Techniques CHAPTER 3 XMLHttpRequest Object CHAPTER 4 Data Formats

Ajax Development with ASP.NET 2.0

Modern Web Development From Angle Brackets to Web Sockets

sessionx Desarrollo de Aplicaciones en Red Web Applications History (1) Content History (2) History (3)

Adding Panoramas to Google Maps Using Ajax

How To Write A Web Server In Javascript

Web application Architecture

Web Development. Owen Sacco. ICS2205/ICS2230 Web Intelligence

Introduction to web development and JavaScript

WWW. World Wide Web Aka The Internet. dr. C. P. J. Koymans. Informatics Institute Universiteit van Amsterdam. November 30, 2007

Developing a Web Server Platform with SAPI Support for AJAX RPC using JSON

LabVIEW Internet Toolkit User Guide

Getting Started Guide with WIZ550web

Designing and Implementing an Online Bookstore Website

SUBJECT CODE : 4074 PERIODS/WEEK : 4 PERIODS/ SEMESTER : 72 CREDIT : 4 TIME SCHEDULE UNIT TOPIC PERIODS 1. INTERNET FUNDAMENTALS & HTML Test 1

Webmail Using the Hush Encryption Engine

4.2 Understand Microsoft ASP.NET Web Application Development

AJAX. Gregorio López López Juan Francisco López Panea

WIRIS quizzes web services Getting started with PHP and Java

Preface. Motivation for this Book

Rich User Interfaces for Web-Based Corporate Applications

Table of contents. HTML5 Data Bindings SEO DMXzone

Performance Testing Web 2.0

DOM, Jav Ja a v Script a and AJA AJ X A Madalina Croitoru IUT Mont Mon pellier

Network Technologies

Dynamic Web Programming BUILDING WEB APPLICATIONS USING ASP.NET, AJAX AND JAVASCRIPT

CTIS 256 Web Technologies II. Week # 1 Serkan GENÇ

Web. Services. Web Technologies. Today. Web. Technologies. Internet WWW. Protocols TCP/IP HTTP. Apache. Next Time. Lecture # Apache.

Ajax Design and Usability

How to access Answering Islam if your ISP blocks it

Software Requirements Specification. Web Library Management System

ACCREDITATION COUNCIL FOR PHARMACY EDUCATION. CPE Monitor. Technical Specifications

Chapter 12: Advanced topic Web 2.0

HTTP - METHODS. Same as GET, but transfers the status line and header section only.

Protocolo HTTP. Web and HTTP. HTTP overview. HTTP overview

MXSAVE XMLRPC Web Service Guide. Last Revision: 6/14/2012

Website Builder Overview

Accessing Data with ADOBE FLEX 4.6

Load testing with. WAPT Cloud. Quick Start Guide

CONNECTING TO THE DTS WIRELESS NETWORK USING WINDOWS VISTA

How To Test Your Web Site On Wapt On A Pc Or Mac Or Mac (Or Mac) On A Mac Or Ipad Or Ipa (Or Ipa) On Pc Or Ipam (Or Pc Or Pc) On An Ip

The Web: some jargon. User agent for Web is called a browser: Web page: Most Web pages consist of: Server for Web is called Web server:

XML Programming with PHP and Ajax

General principles and architecture of Adlib and Adlib API. Petra Otten Manager Customer Support

GUI and Web Programming

DESIGNING HTML HELPERS TO OPTIMIZE WEB APPLICATION DEVELOPMENT

Chapter 3: Web Paradigms and Interactivity

HireDesk API V1.0 Developer s Guide

How to test and debug an ASP.NET application

vcenter Orchestrator Developer's Guide

Technical documentation

Web Content Management System Powered by Ajax

Course Information Course Number: IWT 1229 Course Name: Web Development and Design Foundation

If you wanted multiple screens, there was no way for data to be accumulated or stored

Introduction to Ajax

ISI ACADEMY Web applications Programming Diploma using PHP& MySQL

Framework as a master tool in modern web development

IT3503 Web Development Techniques (Optional)

Portals and Hosted Files

AJAX The Future of Web Development?

Advanced Web Development SCOPE OF WEB DEVELOPMENT INDUSTRY

SYSTEM DEVELOPMENT AND IMPLEMENTATION

Front-End Performance Testing and Optimization

NASSI-SCHNEIDERMAN DIAGRAM IN HTML BASED ON AML

Introduction to the. Barracuda Embedded Web-Server

Web application development landscape: technologies and models

Terms and Definitions for CMS Administrators, Architects, and Developers

Unlocking the Java EE Platform with HTML 5

Administrator s Guide

10CS73:Web Programming

OIT 307/ OIT 218: Web Programming

Getting Started Guide for Developing tibbr Apps

Outline Definition of Webserver HTTP Static is no fun Software SSL. Webserver. in a nutshell. Sebastian Hollizeck. June, the 4 th 2013

HP LoadRunner. Software Version: Ajax TruClient Tips & Tricks

HTTP. Internet Engineering. Fall Bahador Bakhshi CE & IT Department, Amirkabir University of Technology

Internet Technologies. World Wide Web (WWW) Proxy Server Network Address Translator (NAT)

REST web services. Representational State Transfer Author: Nemanja Kojic

Application layer Web 2.0

Benjamin Carlson Node.js SQL Server for Data Analytics and Multiplayer Games Excerpt from upcoming MQP-1404 Project Report Advisor: Brian Moriarty

How Web Browsers Work

Overview. In the beginning. Issues with Client Side Scripting What is JavaScript? Syntax and the Document Object Model Moving forward with JavaScript

ASP.NET: THE NEW PARADIGM FOR WEB APPLICATION DEVELOPMENT

Contents. 2 Alfresco API Version 1.0

Team Members: Christopher Copper Philip Eittreim Jeremiah Jekich Andrew Reisdorph. Client: Brian Krzys

Web Design Specialist

ICT. Universityy. in any

Distance Examination using Ajax to Reduce Web Server Load and Student s Data Transfer

Transcription:

What is AJAX? Ajax Asynchronous JavaScript and XML Ronald J. Glotzbach Ajax is not a technology Ajax mixes well known programming techniques in an uncommon way Enables web builders to create more appealing user interfaces What is Ajax? (cont.) Asynchronous: The JavaScript makes the request to the server while you continue to interact with the webpage without a page reload. Components: Dynamic HTML JavaScript XML Traditional Client-Server Interaction C L I E N T Web Page Web Page Web Page Web Page HTTP RESPONSE HTTP REQUEST HTTP REQUEST HTTP RESPONSE HTTP RESPONSE HTTP REQUEST S E R V E R WEB SERVER Ajax Client-Server Interaction C L I E N T S E R V E R W e b P a g e A j a x W E B S E R V E R What is Ajax? (cont.) Ajax provides an extra layer of processing between the web page and the web server. This layer is often called: Ajax Engine Ajax Framework 1

Rich User Experience A rich user experience is similar to what a desktop application can give you. Fluid, quick, interactive components Traditional web pages, while useful and effective, typically do not give you that rich user experience XMLHTTPRequest When you click a link or submit a form, you send an HTTP Request to the server. Asynchronous Sending that HTTP Request without navigating and requesting a whole page XMLHTTPRequest This is a JavaScript object Makes an HTTP Request behind the scenes XMLHTTPRequest (cont.) Can call a static XML file, which would not require any server-side code. Can call a server-side application for additional processing, such as database interaction. When Should I use Ajax? When you only need to update part of a page. Changing an image Updating fields Responding to users Example: When creating a new user checking to make sure the UserID entered is available while the user continues to enter data in the rest of the form When Should I not use Ajax? While Ajax is an attractive alternative, there are cases where it detracts from the user experience instead of adding to it. When a form is completely filled out. Click a submit button to send the request When the user will be navigating anyway Small sites may not sufficiently benefit considering the additional code required and increased complexity. Security Issues Most security issues surrounding Ajax are pre-existing Although, Ajax does use more client-side code that is visible to users Coder must be cognizant not to place sensitive information there i.e.: Make sure server-side code takes care of database connections, etc. Make sure business logic resides on the server Validate data on the server before using it 2

Client-Side Issues JavaScript is still implemented differently across platforms The Document Object Model (DOM) is handled differently between browsers and between versions of the same browser With the given complexity of Ajax, it is even more important now to test on multiple browsers Ajax won t fix a bad design Good web design still applies: Write for multiple browsers and validate your code Comment your code well so you can debug it later Use graphics small in size so they load quickly Make sure your choices of colors, backgrounds, font sizes, and styles follow proper web design techniques Create an Instance Ajax In Mozilla, Opera, etc.: var request = new XMLHTTPRequest(); Code & Examples However, in Internet Explorer: var request = new ActiveXObject( Microsoft.XMLHTTP ); However, some versions of Internet Explorer have different versions of the MSXML parser: var request = new ActiveXObject( Msxml2.XMLHTTP ); Create an Instance (cont.) Therefore, we need an example that will work across platforms and across multiple versions of the same web browser Create an Instance (cont.) function getxmlhttprequest() var request = false; try /* e.g. Firefox */ request = new XMLHttpRequest(); catch(error1) try /* some versions IE */ request = new ActiveXObject("Msxml2.XMLHTTP"); catch(error2) try /* some versions IE */ request = new ActiveXObject("Microsoft.XMLHTTP"); catch(error3) request = false; return request; 3

Create an Instance (cont.) Then, to generate an HTTP Request: var request = new getxmlhttprequest(); This calls the function (on the previous slide) and returns the appropriate XMLHTTPRequest object Introducing try-catch Similar to placing an @ in front of a PHP statement Similar to placing On Error Resume Next in ASP code A try-catch block allows the page to continue processing and not crash when an error occurs Additionally, in the catch block, you can write customized code to deal with the error XMLHTTPRequest Properties XMLHTTPRequest Methods onreadystatechange Determines which event handler will be called when the object s readystate property changes abort() Stops the current request readystate responsetext responsexml status statustext Integer reporting the status of the request: 0 = uninitialized 1 = loading 2 = loaded 3 = interactive 4 = completed Data returned by the server in text string form Data returned by the server expressed as a document object HTTP status code returned by server HTTP reason phrase returned by server getallresponseheaders() getresponseheader(x) open( post, URL, true ) setrequestheader( x, y ) send(content) Returns all headers as a string Returns the value of header x as a string Specifies the HTTP method (for example, get or post), the target URL, and whether the request should be handled asynchronously (if yes, true --- if not, false) Sets a name equal value pair, x=y, and assigns it to the header to be sent with the request Sends the request, optionally with post data HTTP Response Status Codes Sending an HTTP Request 200 OK 204 No Content 301 Moved Permanently 401 Not Authorized 403 Forbidden The request succeeded The document contains no data The resource has permanently moved to a different URL The request needs user authentication The server has refused to fulfill the request // function from previous slide goes up here var request = getxmlhttprequest(); function callajax() // declare and initialize a variable var lastname = Smith ; // build the URL of the server script we wish to call var url = "serverscript.php?username=" + lastname; 404 Not Found The requested resource does not exist on the server // use the XMLHTTPRequest object to open a server connection request.open("get", url, true); 408 Request Timeout 500 Server Error The client failed to send a request in the time allowed by the server Due to a malfunctioning script, server configuration error, or something similar // prepare a function responseajax() to run when the response has arrived request.onreadystatechange = responseajax; // and finally send the request request.send(null); 4

responseajax function Example 1 function responseajax() // we are only interested in readystate of 4, i.e. "loaded" if(request.readystate == 4) // if server HTTP response is "OK" if(request.status == 200) alert("the server said: " + request.responsetext); else // issue an error message for any other HTTP response alert("an error has occurred: " + request.statustext); Get Server Time Use PHP to generate XML output Call the PHP using Ajax Use JavaScript to parse and display the XML Ajax Example 1 Example 2 Get Text From the Server Use PHP to echo strings of text Call the PHP using Ajax Use JavaScript to display the text from the server Ajax Example 2 Example 3 Get Text From the Server The same example as #2, but using ASP Use ASP to Response.Write strings of text Call the ASP using Ajax Use JavaScript to display the text from the server Ajax Example 3 Returning Text Now, imagine instead of just returning text in an echo or Response.Write that some processing occurs on the server, perhaps verification of a username, and the result returned determines what text you display in the browser. AHAH Asynchronous HTML and HTTP 5

Asynchronous HTML and HTTP You may see this referred to as different acronyms. This is essentially a subset of Ajax JAH Just Asynchronous HTML HAJ HTML and JavaScript (also called Dynamic HTML) AHAH Asynchronous HTML and HTTP xmljs XML and JavaScript (this is a popular term) Example 4 Retrieving content from a website Use PHP to retrieve keywords from a website, if a keywords meta tag exists. Type in a website into the form Submit the form to have Ahah call the PHP Write out the result from the PHP to the browser Example 4 AHAH Really, examples 2, 3, and 4 are considered AHAH because no XML was involved with those examples. Ajax (cont.) Now, let s put the x in Ajax The level of coding steps up a notch as more extensive JavaScript is used to navigate through the XML DOM XML DOM Properties XML DOM Node Methods childnodes Array of child nodes firstchild The first child node AppendChild() Add a new child node lastchild The last child node HasChildNodes() True if this node has children nodename Name of the node RemoveChild() Deletes a child node nodetype Type of node nodevalue Value contained in the node nextsibling Next node sharing the same parent previoussibling Previous node sharing the same parent parentnode Parent of this node 6

Document Methods Example 5 CreateAttribute() CreateElement() CreateTextNode() GetElementsByTagName() GetElementsById() Make a new attribute for an element Make a new document element Make a text item Create an array of tagnames Find an element by its ID RSS Headline Reader Pass a URL to an RSS feed to PHP PHP reads the contents of the RSS feed using the curl library and echo s it out Use the DOM to navigate the output and display the contents Ajax Example 5 Example 6 Standalone applications Read Directly from XML Point Ajax to the xml file Use the DOM to navigate the XML and display the contents Ajax Example 6 It is possible to create standalone applications in Ajax meaning that no server is needed A standalone application should be able to be copied to a new location, such as your desktop, and function the same as if it were on a server. Pulling JavaScript out as include files An added layer of protection, if you will. The typical user has to be savvy enough to decipher HTML, find the.js file, then navigate to that.js file in the browser explicitly in order to view it. This is still NOT secure Example 7 Example 6 with JavaScript pulled out and placed in.js files Script include statements used within the html Example 7 7

Web Services & REST Web Service A server-side application that you typically interface with using XML and HTTP. It is not a website it is an application that you send a request to, the web service processes the request, and sends you back a result. REST Representational State Transfer REST REST is sometimes referred to as: XML over HTTP XML/HTTP Two main principals of REST: Resources are represented by URLs Each web service has a unique URL Operations are carried out via HTTP Get, Post, Put, Delete REST Web Service An example call: http://del.icio.us/api/[user]/bookmarks/?start=1&end=2 Another example call: http://xml.amazon.com/onca/xml3?t=[id]&devt=[token]&manufacturersearch=sams&mode=books&s ort=+salesrank&offer=all&type=lite&page=1&f=xml SOAP Simple Object Access Protocol An XML-based messaging protocol Contains: envelope (defines doc as a SOAP request) Body (info about the call & expected responses) optional header (supplementary info) optional fault (supplementary info) SOAP Example Request SOAP Example Response <?xml version="1.0"?> <soap:envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingstyle="http://www.w3.org/2001/12/soap-encoding"> <soap:body xmlns:m="http://www.example.org/stock"> <m:getstockprice> <m:stockname>ibm</m:stockname> </m:getstockprice> </soap:body> </soap:envelope> HTTP/1.1 200 OK Content-Type: application/soap+xml; charset=utf-8 Content-Length: nnn <?xml version="1.0"?> <soap:envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingstyle="http://www.w3.org/2001/12/soap-encoding"> <soap:body xmlns:m="http://www.example.org/stock"> <m:getstockpriceresponse> <m:price>34.5</m:price> </m:getstockpriceresponse> </soap:body> </soap:envelope> 8

Ajax Issues The Back Button Every browser has one What happens when it s clicked? Additional programming may be required for you to track your own state and you may have to persuade users not to use the back button Ajax Issues (cont.) Bookmarking Try using some of the Ajax examples and then bookmarking the page at a specific point. When you navigate back to your bookmark, the state of the page is not maintained. Ajax Issues (cont.) Spiders Ajax does not typically return the most accurate information for search engine spiders Ajax has interactive content whereas many spiders search for static content You may need to create a static site map or other means to allow search engine spiders to properly index your site. XOAD XML Object-oriented Application Development (XOAD) XOAD is an Ajax toolkit written in PHP www.xoad.org http://sourceforge.net/projects/xoad http://forums.xoad.org/ Ajax The End 9