AJAX Asynchronous JavaScript and XML 1. AJAX Outline What is AJAX? Benefits Real world examples How it works 2.

Slides:



Advertisements
Similar presentations
Modern JavaScript Develop And Design Instructor’s Notes Chapter 11– Ajax Modern JavaScript Design And Develop Copyright © 2012 by Larry Ullman.
Advertisements

AJAX Presented by: Dickson Fu Dimas Ariawan Niels Andreassen Ryan Dial Jordan Nielson CMPUT 410 University of Alberta 2006.
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,
AJAX asynchronous server-client communication. Test.
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.
Prof. James A. Landay University of Washington Spring 2008 Web Interface Design, Prototyping, and Implementation Rich Internet Applications: AJAX, Server.
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
Lecture 12 – AJAX SFDV3011 – Advanced Web Development Reference: 1.
ASP.NET + Ajax Jesper Tørresø ITNET2 F08. Ajax Ajax (Asynchronous JavaScript and XML) A group of interrelated web development techniques used for creating.
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.
06/10/2015AJAX 1. 2 Introduction All material from AJAX – what is it? Traditional web pages and operation Examples of AJAX use Creating.
XMLHttpRequest Object When Microsoft Internet Explorer 5.0 introduced a rudimentary level of XML support, an ActiveX library called MSXML was also introduced,
Ajax. –Asynchronous JavaScript and XML –Umbrella term for technologies that often: Use client-side scripting for layout and formatting Use less than full.
Ajax In Action The Journey into Web2.0 Presented by Eric Pascarello.
AJAX (also known as: XMLHTTP, Remote Scripting, XMLHttpRequest, etc.) Matt Warden.
AJAX محمد احمدی نیا 2 Of 27 What is AJAX?  AJAX = Asynchronous JavaScript and XML.  AJAX is not a new programming language, but.
Fall 2006 Florida Atlantic University Department of Computer Science & Engineering COP 4814 – Web Services Dr. Roy Levow Part 2 – Ajax Fundamentals.
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.
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:
AJAX Asynchronous JavaScript & XML A short introduction.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
JQuery and AJAX WEB Technologies : PHP Programming Language.
SE-2840 Dr. Mark L. Hornick 1 Introduction to Ajax Asynchronous Javascript And XML.
Web Programming JAvaScript Ajax Programming Web Programming /38.
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.
CHAPTER 8 AJAX & JSON WHAT IS AJAX? Ajax lets you…
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.
AJAX CS456 Fall Examples Where is AJAX used? Why do we care?
PHP and AJAX. Servers and Clients For many years we tried to move as much as possible to the server. Weak clients, poor bandwidth, browser compatibility..
1 AJAX. AJAX – Whatzit? Asynchronous (content loading)‏ Javascript (logic & control)‏ And XML (request handling)‏
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.
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.
Ajax SUBMITTED BY NITIN RAMANI C.S.E 3 rd Y 5 th S R.N CS SUBMITTED TO PRO. PUSHPARAJ PATEL SIR.
Introduction to AJAX Pat Morin COMP Outline What is AJAX? – History – Uses – Pros and Cons An XML HTTP Transaction – Creating an XMLHTTPRequest.
What is AJAX ? Asynchronous Javascript and XML.
JavaScript and Ajax (Ajax Tutorial)
CSE 154 Lecture 11: AJAx.
AJAX AJAX = Asynchronous JavaScript and XML.
CS 371 Web Application Programming
XMLHttp Object.
AJAX – Asynchronous JavaScript and XML
AJAX.
AJAX (Asynchronous JavaScript and XML.)
CSE 154 Lecture 11: AJAx.
AJAX and JSP ISYS 350.
CSE 154 Lecture 22: AJAX.
ISC440: Web Programming 2 AJAX
JavaScript & jQuery AJAX.
Chengyu Sun California State University, Los Angeles
AJAX CS-422 Dick Steflik.
Web Technology Even Sem 2015
Chengyu Sun California State University, Los Angeles
AJAX and JSP ISYS 350.
Presentation transcript:

AJAX Asynchronous JavaScript and XML 1

AJAX Outline What is AJAX? Benefits Real world examples How it works 2

What is AJAX? Asynchronous JavaScript and XML (AJAX) Web development technique for creating web applications Makes web pages more responsive by exchanging small amounts of data Allows the web page to change its content without refreshing the whole page A web browser technology independent of web server software 3

Benefits Improves the user experience – Analyzing information typed into browser in real time – Provide a richer experience – Increases responsiveness of web pages Improve bandwidth utilization – Only data which is required is retrieved from the server 4

Real World Examples Google Maps ( (slidable maps) My Yahoo! ( (shuffling windows) 5

How it works AJAX runs in your browser Works with asynchronous data transfers(HTTP requests) between the browser and the web server Http requests are sent by JavaScript calls without having to submit a form XML is commonly used as the format for receiving server data but plain text may be used as well 6

1 – XMLHttpRequest object A page element must make a JavaScript call The JavaScript function must create an XMLHttpRequest object which is used to contact the server JavaScript must determine whether the client is IE or Firefox http = new ActiveXObject("Microsoft.XMLHTTP"); (IE) http = new XMLHttpRequest(); (Mozilla) 7

1 – XMLHttpRequest object Custom function to return XMLHttpRequest object for all possible types of browser function create_ajax() { var xmlhttp = null; if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } return xmlhttp; } 8

2 - Sending the request Once the XMLHttpRequest object has been created it must be set up to call the server var ajax = create_ajax(); ajax.onreadystatechange = function() { response(ajax); } ajax.open(method, url, async); ajax.send(str); The code above utilizes the XMLHttpRequest object to contact the server and retrieve server data When the response returns result the JavaScript function response(ajax) will be invoked and then can update the page 9

3 - Handling the Response Implementation of the JavaScript function which will be used to handle the response (Event Handler): function response(ajax){ /* Debug ajax state and status */ //alert(ajax.readyState + " - " + ajax.status); if (ajax.readyState == 4 && ajax.status == 200) { var str = ajax.responseText; document.getElementById("result").innerHTML = str; } Now the page has communicated with the server without having to refresh the entire page 10

readyState & status property The readyState property defines the current state of the XMLHttpRequest object Possible values for the readyState For the status it can either 200 (“OK”), 404 (Page not found), or 0 (cross domain request restriction) StateDescription 0The request is not initialized 1The request has been setup 2The request has been submitted 3The request is in process 4The request is completed 11

Example Server Client plus2num.html plus2num.php count(); ??? echo $_REQUEST["num1"] + $_REQUEST["num2"];... AJAX (POST/GET) AJAX(text/plain) [1] [2] [3] [4] [5] 12

Example plus2num.html (body section) Num1: + Num2: = ??? [1] 13

Example plus2num.html (head section)... ? ? ? function count() { var str = "num1=" + document.f.num1.value + "&" + "num2=" + document.f.num2.value; var ajax = create_ajax(); ajax.onreadystatechange = function() { response(ajax); } /* GET method */ ajax.open("GET", " + str, true); ajax.send(); /* POST method */ //ajax.open("POST", " true); //ajax.setRequestHeader("Content-type", // "application/x-www-form-urlencoded"); //ajax.send(str); } [2] [3] [4] / [5] 14 Refer to slide #10

Example plus2num.php <?php header("Content-type:text/plain"); header("Access-Control-Allow-Origin: *"); echo $_REQUEST["num1"] + $_REQUEST["num2"]; ?> Disable cross domain request restriction Change the default “text/html” PHP header 15

Example (AJAX using jQuery) plus2num_jquery.html (head section) $(document).ready(function(){ $("input#clkbtn").click(function(){ var str = $("form").serialize(); /* POST/GET method */ $("span").load(" str); }); }); [2] [3] / [4] / [5] [1] 16

Example (AJAX using jQuery) plus2num_jquery.html (body section) Num1: + Num2: = ??? 17

Example (AJAX using jQuery) plus2num_jquery.html (head section) Other options for get/post requests but need extra setResult function. $(document).ready(function(){ $("input#clkbtn").click(function(){ var str = $("form").serialize(); /* GET method */ //$.get(" + str, // function(data, status){ setResult(data, status); }); /* POST method */ //$.post(" str, // function(data, status){ setResult(data, status); }); }); }); function setResult(data, status) { $("span").text(data); } 18