HTML5 AJAX & JSON APIs http://www.profburnett.com.

Slides:



Advertisements
Similar presentations
JavaScript and AJAX Jonathan Foss University of Warwick
Advertisements

JQUERY/AJAX ALIREZA KHATAMIAN DELARAM YAZDANSEPAS.
JSON IDU0075 Sissejuhatus veebiteenustesse.  JSON stands for JavaScript Object Notation  JSON is lightweight text-data interchange format  JSON is.
AJAX Presented by: Dickson Fu Dimas Ariawan Niels Andreassen Ryan Dial Jordan Nielson CMPUT 410 University of Alberta 2006.
WHAT IS AJAX? Zack Sheppard [zts2101] WHIM April 19, 2011.
Chapter 6 DOJO TOOLKITS. Objectives Discuss XML DOM Discuss JSON Discuss Ajax Response in XML, HTML, JSON, and Other Data Type.
JQuery CS 268. What is jQuery? From their web site:
Chris Pinski.  History  What is Ajax  Who uses Ajax  Underlying Technologies  SE Aspect  Common Problems  Conclusion.
Ajax (Asynchronous JavaScript and XML). AJAX  Enable asynchronous communication between a web client and a server.  A client is not blocked when an.
JavaScript & jQuery the missing manual Chapter 11
Databases.  Multi-table queries  Join ▪ An SQL JOIN clause is used to combine rows from two or more tables, based on a common field between them. 
CSCI 6962: Server-side Design and Programming Introduction to AJAX.
Lecture 12 – AJAX SFDV3011 – Advanced Web Development Reference: 1.
RESTful applications Norman White. REST Representational state transfer Key concepts – Client Server architecture built on transferring resources between.
06/10/2015AJAX 1. 2 Introduction All material from AJAX – what is it? Traditional web pages and operation Examples of AJAX use Creating.
HTML5 Communication. The Setup Somewhere on the web, a server makes a ”service” available, that we wish to use in a web application The service may offer.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Cross Site Integration “mashups” cross site scripting.
Lecture 9: AJAX, Javascript review..  AJAX  Synchronous vs. asynchronous browsing.  Refreshing only “part of a page” from a URL.  Frameworks: Prototype,
ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.
CISC 3140 (CIS 20.2) Design & Implementation of Software Application II Instructor : M. Meyer Address: Course Page:
JQuery JavaScript is a powerful language but it is not always easy to work with. jQuery is a JavaScript library that helps with: – HTML document traversal.
Creating Dynamic Webpages
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
AJAX James Kahng. Congrats Jack Guo for Angular entryentry This week’s coding challenge at end of talk.
AJAX Asynchronous JavaScript and XML 1. AJAX Outline What is AJAX? Benefits Real world examples How it works 2.
JQuery and AJAX WEB Technologies : PHP Programming Language.
AJAX. Ajax  $.get  $.post  $.getJSON  $.ajax  json and xml  Looping over data results, success and error callbacks.
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.
Dave Salinas. What is XML? XML stands for eXtensible Markup Language Markup language, like HTML HTML was designed to display data, whereas XML was designed.
AJAX CS456 Fall Examples Where is AJAX used? Why do we care?
JavaScript, Sixth Edition Chapter 11 Updating Web Pages with Ajax.
JSON (Copied from and from Prof Da Silva) Week 12 Web site:
JavaScript and Ajax Week 10 Web site:
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.
11 jQuery Web Service Client. 22 Objectives You will be able to Use JSON (JavaScript Object Notation) for communcations between browser and server methods.
AJAX. Objectives Understand and apply AJAX Using AJAX in DOJO library.
WELCOME MIDHUN SUDHAKAR twitter.com/midhunopus in.linkedin.com/pub/midhunsudhakar/86/a65/a9.
National College of Science & Information Technology.
Storing Data.
JavaScript and Ajax (Ajax Tutorial)
CSE 154 Lecture 11: AJAx.
Not a Language but a series of techniques
AJAX AJAX = Asynchronous JavaScript and XML.
AJAX and REST.
Database Systems Week 12 by Zohaib Jan.
Application with Cross-Platform GUI
AJAX.
Consuming Java Script Object Notation (JSON) feeds
AJAX.
CSE 154 Lecture 11: AJAx.
Session V HTML5 APIs - AJAX & JSON
CSE 154 Lecture 22: AJAX.
jQuery form submission
ISC440: Web Programming 2 AJAX
HTML Level II (CyberAdvantage)
2017, Fall Pusan National University Ki-Joune Li
JavaScript & jQuery AJAX.
MIS JavaScript and API Workshop (Part 3)
Introduction to AJAX and JSON
Master a Skill / Learn for Life
Advanced Concepts and AJAX
Introduction to AJAX and JSON
Ajax and JSON Jeremy Shafer Department of MIS Fox School of Business
Ajax and JSON Jeremy Shafer Department of MIS Fox School of Business
XML/JSON/AJAX Master a Skill / Learn for Life
MIS Professor Sandvig MIS 424 Professor Sandvig
JSON: JavaScript Object Notation
Presentation transcript:

HTML5 AJAX & JSON APIs http://www.profburnett.com

Class Outline AJAX JSON JSONP What Is Ajax? Ajax: The Basics Ajax the jQuery Way AJAX Exercises JSON What is JSON? JSON Array Object Example Much Unlike XML Because JSON Syntax JSON Objects & Arrays JSON HTTP Request Example JSON Exercises JSONP What is JSONP? How JSONP it works Cross-domain requests using a proxy server Security concerns 12/28/2018 Copyright © Carl M. Burnett

What is AJAX? AJAX = Asynchronous JavaScript and XML. AJAX is a technique for creating fast and dynamic web pages. AJAX allows web pages to be updated asynchronously. Exchanging small amounts of data with the server Updates parts of a web page, without reloading the whole page. Examples of applications using AJAX: Google Maps, Gmail, YouTube, and Facebook.

XMLHttpRequest Processes the returned data using JavaScript An event happens: XMLHttpRequest Object Created HttpRequest Sent Web Server processes the HttpRequest Creates a response and sends data back to Client. Processes the returned data using JavaScript Updates page content 7/14/2013 Copyright © Carl M. Burnett

Ajax the jQuery Way Using the load() Method - Loads an HTML file into a specified element on the page. Traditional Example: Short list of news headlines. Page loads - Five most recent news stories appear. Add links to let visitors choose what news stories are displayed. Linking are displayed in separate web pages Force visitors to move onto another web page. (non-AJAX) AJAX Example: Load the selected news stories into the news headlines box on the page. Each visitor click - browser requests a new HTML file for the headline box from the server Places that HTML into the headlines box Never leaves current page.

The get() and post() Methods QUERY STRING URL http://www.chia-vet.com/ products.php?prodID=18&sessID=1234 name/value pairs GET Method: $.get('rateMovie.php','rating=5'); POST method: $.post('rateMovie.php','rating=5'); $.post('rateMovie.php','rating=5&user=Bob');

The get() and post() Methods OBJECT LITERAL TO STORE DATA { name1: 'value1', name2: 'value2' } var data = { rating: 5 }; $.post('rankMovie.php', { rating: 5 });

The get() and post() Methods JQUERY’S SERIALIZE() FUNCTION FOR FORM DATA var str = $("formData").serialize(); $.get('login.php',formData,loginResults);

The get() and post() Methods Processing Data from the Server 1 $('#message a').click(function() { 2 var href=$(this).attr('href'); 3 var querystring=href.slice(href.indexOf('?')+1); 4 $.get('rate.php', querystring, processResponse); return false; // stop the link }); selects every link (<a> tag) inside of another tag with an ID of message extracts the href attribute of the link extracts just the part after the ? in the URL using the slice() method the Ajax request using the GET method - results goes to “Callback Function” stops the normal link behavior and prevents the web browser from unloading the current page

The get() and post() Methods Callback Function 1 function processResponse(data) { 2 var newHTML; 3 newHTML = '<h2>Your vote is counted</h2>'; 4 newHTML += '<p>The average rating for this movie is '; 5 newHTML += data + '.</p>'; 6 $('#message').html(newHTML); 7 }

The get() and post() Methods Handling Errors $.get('rate.php', querystring,processResponse).error(errorResponse); function errorResponse() { var errorMsg = "Your vote could not be processed right now. "; errorMsg += "Please try again later."; $('#message').html(errorMsg); }

jQuery AJAX Exercises Complete the following jQuery AJAX Exercises on W3Schools Website. jQuery AJAX Example jQuery load() Method jQuery $.get() Method jQuery $.post() Method

What is JSON? JSON stands for JavaScript Object Notation JSON is a lightweight data-interchange format JSON is language independent * JSON is "self-describing" and easy to understand

JSON Array Object Example { "employees":[ {"firstName":"John", "lastName":"Doe"}, {"firstName":"Anna", "lastName":"Smith"}, {"firstName":"Peter", "lastName":"Jones"} ] }

Much Unlike XML Because JSON doesn't use end tag JSON is shorter JSON is quicker to read and write JSON can use arrays

JSON Syntax JSON syntax is derived from JavaScript object notation syntax: Data is in name/value pairs Data is separated by commas Curly braces hold objects Square brackets hold arrays

JSON Data - A Name and a Value "firstName" : "John" JSON values can be: A number (integer or floating point) A string (in double quotes) A Boolean (true or false) An array (in square brackets) An object (in curly braces) null

JSON Objects JSON Arrays {"firstName":"John", "lastName":"Doe"} { "employees":[     {"firstName":"John", "lastName":"Doe"},     {"firstName":"Anna", "lastName":"Smith"},     {"firstName":"Peter", "lastName":"Jones"} ] }

JSON Uses JavaScript Syntax { "employees":[     {"firstName":"John", "lastName":"Doe"},     {"firstName":"Anna", "lastName":"Smith"},     {"firstName":"Peter", "lastName":"Jones"} ] } // returns John Doe employees[0].firstName + " " + employees[0].lastName;

JSON HTTP Request Example 1: Create an array of objects. 2: Create a JavaScript function to display the array. 3: Create a text file 4: Read the text file with an XMLHttpRequest HTTP Request Example

What is JSONP? JSONP (which stands for JSON with padding) Technique to overcome: cross-domain restrictions imposed by browsers. allows data to be retrieved from foreign systems.

How JSONP it works Function call - myResponseFunction() It is the "P" of JSONP (the "padding" around the pure JSON, or according to some the "prefix". myResponseFunction({"Name": "Foo", "Id": 1234, "Rank": 7});

How JSONP it works Server response that includes the JSONP function. JSONP does not work with JSON-formatted results. The JSONP function invocation gets sent back The payload that the function receives, must be agreed-upon by the client and server. The browser provides the name of the callback function Named query parameter value - typically name “jsonp” or “callback” <script type="application/javascript" src="http://server.example.com/Users/1234?callback=parseResponse"> </script>

Cross-domain requests using a proxy server Newer browsers support CORS relax this constraint Cooperating proxy server does not have such restrictions Relays a browser request to a server in a separate domain Stores the result. Returns the JSON payload when the browser makes a second request. The xd_arbiter.php used by Facebook's JS SDK is a popular example of this cooperating server technique.[6]

Security Concerns Untrusted third-party code Callback name manipulation and Reflected File Download Cross-site request forgery – (Exclusive use of cookies for determining if a request is authorized) Rosetta Flash - Adobe Flash Player (Fixed 2014)

JSONP Exercise Adding a Flickr Feed to Your Site

Class Review AJAX JSON JSONP What Is Ajax? Ajax: The Basics Ajax the jQuery Way AJAX Exercises JSON What is JSON? JSON Array Object Example Much Unlike XML Because JSON Syntax JSON Objects & Arrays JSON HTTP Request Example JSON Exercises JSONP What is JSONP? How JSONP it works Cross-domain requests using a proxy server Security concerns 12/28/2018 Copyright © Carl M. Burnett