Introduction to AJAX and JSON

Slides:



Advertisements
Similar presentations
JQUERY/AJAX ALIREZA KHATAMIAN DELARAM YAZDANSEPAS.
Advertisements

AJAX Presented by: Dickson Fu Dimas Ariawan Niels Andreassen Ryan Dial Jordan Nielson CMPUT 410 University of Alberta 2006.
IS 360 Course Introduction. Slide 2 What you will Learn (1) The role of Web servers and clients How to create HTML, XHTML, and HTML 5 pages suitable for.
Ajax Dr Jim Briggs WEBP Ajax1. 2 Ajax Asynchronous JavaScript And XML Method of creating more interactive web applications Moves more of the application.
Cloud Computing Lecture #7 Introduction to Ajax Jimmy Lin The iSchool University of Maryland Wednesday, October 15, 2008 This work is licensed under a.
Chris Pinski.  History  What is Ajax  Who uses Ajax  Underlying Technologies  SE Aspect  Common Problems  Conclusion.
Introduction to AJAX AJAX Keywords: JavaScript and XML
JavaScript & jQuery the missing manual Chapter 11
Creating a Basic Web Page
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. 
CS 4720 RESTfulness and AJAX CS 4720 – Web & Mobile Systems.
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. –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.
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.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
Summer 2007 Florida Atlantic University Department of Computer Science & Engineering COP 4814 – Web Services Dr. Roy Levow Part 1 – Introducing Ajax.
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.
INTRODUCTION JavaScript can make websites more interactive, interesting, and user-friendly.
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.
October 7 th, 2010 SDU Webship. What did we learn last week? jQuery makes it really easy to select elements and do stuff with them. jQuery can process.
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.
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
AJAX CS456 Fall Examples Where is AJAX used? Why do we care?
Introduction to AJAX MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/4/2016.
National College of Science & Information Technology.
JavaScript, AJAX and JSON MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/9/2016.
Introduction to JavaScript MIS 3502, Fall 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 9/29/2016.
Web Technologies Computing Science Thompson Rivers University
JavaScript and Ajax (Ajax Tutorial)
Data Virtualization Tutorial… CORS and CIS
AJAX and REST.
Application with Cross-Platform GUI
AJAX.
Asynchronous Java script And XML Technology
AJAX.
Prepared for Md. Zakir Hossain Lecturer, CSE, DUET Prepared by Miton Chandra Datta
Introduction to AJAX MIS 3502 Jeremy Shafer Department of MIS
Introduction to JavaScript
Introduction to AJAX MIS 3502 Jeremy Shafer Department of MIS
IS 360 Course Introduction
A second look at JavaScript
Web Browser server client 3-Tier Architecture Apache web server PHP
Ajax and JSON (jQuery part 2)
Introduction to AJAX Sue Brandreth.
JavaScript & jQuery AJAX.
Secure Web Programming
HTML and CSS MIS 2402 Jeremy Shafer Department of MIS
Sending a text message (and more)
Form Validation, Part 2 (with jQuery, HTML5, and CSS)
MIS JavaScript and API Workshop (Part 3)
An Introduction to Animation
An Introduction to JavaScript
Sending a text message (and more)
Introduction to World Wide Web
Introduction to JavaScript
An introduction to jQuery
Introduction to MIS2402 MIS MIS2402 Jeremy Shafer Department of MIS
Web Technologies Computing Science Thompson Rivers University
An introduction to jQuery
Introduction to AJAX and JSON
Ajax and JSON Jeremy Shafer Department of MIS Fox School of Business
HTML MIS 2402 Jeremy Shafer Department of MIS Fox School of Business
Sending a text message (and more)
Ajax and JSON Jeremy Shafer Department of MIS Fox School of Business
Presentation transcript:

Introduction to AJAX and JSON MIS 2402 Jeremy Shafer Department of MIS Fox School of Business Temple University

Visualizing what we have done so far… Web Server URL, referencing a web page Browser JavaScript Engine HTTP Response Database This is called a “round trip”. Round trips are relatively expensive (in terms of computing power). We’ve been using JavaScript form validation to prevent unnecessary round trips. JavaScript/jQuery run here, in the browser, and do not interact with any resource outside the browser.

The DOM (Document Object Model) JavaScript can change all the HTML elements in the page JavaScript can change all the HTML attributes in the page JavaScript can change all the CSS styles in the page JavaScript can remove existing HTML elements and attributes JavaScript can add new HTML elements and attributes JavaScript can react to all existing HTML events in the page JavaScript can create new HTML events in the page All of these activities are accomplished through the properties and methods of objects. NEW FOR TODAY: We can use data, provided by AJAX, and present it in the DOM. Source: http://www.w3schools.com/js/js_htmldom.asp

An AJAX call we see every day…

So, what’s AJAX? AJAX is short for Asynchronous JavaScript and XML It is the combination of these technologies, not a separate technology in itself It’s kind of sneaky…

AJAX uses JavaScript to call web services Web Server URL, referencing a web page Browser JavaScript Engine HTTP Response (the WHOLE page) Database Less of this

AJAX uses JavaScript to call resources Web server HTTP Request Browser (just the data we need) JavaScript Engine Database More of this

AJAX uses JavaScript to call Resources Not this Jesse James!  The term "Ajax" was publicly stated on 18 February 2005 by Jesse James Garrett in an article titled "Ajax: A New Approach to Web Applications", based on techniques used on Google pages. This object acts like a browser, inside the browser. The object is used to retrieve a web resource. XMLHttpRequest()

XMLHttpRequest allows us to do things like this… 

$.getJSON(someurl, function(result) { some things to do }) Or… using jQuery  Yes, there really is a dot here. There’s actually a piece here that we’re intentionally leaving out today. We would use an optional parameter here to send data to someurl $.getJSON(someurl, function(result) { some things to do }) There are other jQuery methods used to do make Ajax calls: .ajax() .load() .get() .post() A list of jQuery Ajax methods can be found here: https://www.w3schools.com/jquery/jquery_ref_ajax.asp This piece is called “the callback function”. It is the function, that runs, when the call to someurl comes back.

Jason and the Argonauts (1963 film) So, what about JSON? This is Jason Not JSON Jason and the Argonauts (1963 film)

JSON JSON is short for JavaScript Object Notation JSON is an alternative to XML A JSON object looks like this:

JSON vs. XML An XML object looks a little like this: <customers> <NameOfInsured>Jeremy Shafer</NameOfInsured> <Spouse>Kimberly Shafer</Spouse> <Dependents> <firstname>Amanda</firstname> <firstname>Tyler</firstname> <firstname>Jordan</firstname> </Dependents> </customer> </customers>

Where is JSON used? Web server HTTP Request Browser How is the data formatted? JSON? XML? Plain text? JavaScript Engine Database

Why JSON and XML are a big deal… Back in the day, if you wanted to exchange data between two systems, you specified the format of a flat file. For example: NameOfInsured, Spouse, Dependent1, Dependent2, Dependent3 Jeremy Shafer, Kimberly Shafer, Amanda, Tyler, Jordan Greg Mathews, Krista Mathews, Melonie, Lauren, William

Why JSON and XML are a big deal (2) But this approach assumed that you could anticipate the quantities of all the attributes. The data transfer file was denormalized So, sometimes an exception would occur because of an unexpected quantity of elements. For example: NameOfInsured, Spouse, Dependent1, Dependent2, Dependent3 Jeremy Shafer, Kimberly Shafer, Amanda, Tyler, Jordan, Ben Greg Mathews, Krista Mathews, Melanie, Lauren, William The data needs to be serialized in order to send it from one system to another without any limitation. Uh oh! Dependent #4!

Then XML came along (circa 1998) XML allowed us to represent an object with unspecified number of attributes, all in a single file. XML was (and still is) verbose JSON emerged as a more streamlined alternative. Originally defined in 2001, with adoption picking up in 2006.

JSON described JSON (JavaScript Object) Notation, is an open standard format that uses human-readable text to transmit data objects consisting of attribute–value pairs. It is used primarily to transmit data between a server and web application, as an alternative to XML. Although originally derived from the JavaScript scripting language, JSON is a language-independent data format. Code for parsing and generating JSON data is readily available in many programming languages. At the end of the day… think key and value pairs in pattern: { “KEY” : “VALUE”, “KEY” : “VALUE” } http://en.wikipedia.org/wiki/JSON

Let’s come back to this… This is the callback function that will execute when the Ajax call is a success. $.getJSON(someurl, function(result) { some things to do}); The URL to visit Result is the simple object returned by the getJSON method. One or more commands. I can use the data in result here!

Let’s slay this beast….