JavaScript, AJAX and JSON MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/9/2016.

Slides:



Advertisements
Similar presentations
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
Advertisements

Nikolay Kostov Telerik Corporation
Krerk Piromsopa. Web Caching Krerk Piromsopa. Department of Computer Engineering. Chulalongkorn University.
ASP.NET + Ajax Jesper Tørresø ITNET2 F08. Ajax Ajax (Asynchronous JavaScript and XML) A group of interrelated web development techniques used for creating.
Class03 Introduction to Web Development with PHP MIS 3501, Fall 2015 Brad Greenwood, PhD MBA Department of MIS Fox School of Business Temple University.
Chapter 8 Cookies And Security JavaScript, Third Edition.
Cookies Web Browser and Server use HTTP protocol to communicate and HTTP is a stateless protocol. But for a commercial website it is required to maintain.
JSON and A Comparison of Scripts. JSON: JavaScript Object Notation Based on a subset of the JavaScript Programming Language provides a standardized data.
 Previous lessons have focused on client-side scripts  Programs embedded in the page’s HTML code  Can also execute scripts on the server  Server-side.
RESTful Web Services What is RESTful?
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.
Class03 Introduction to Web Development (Hierarchy and the IDE) MIS 3501, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University.
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
Class02 More Arrays MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 1/14/2016.
Responsive Web Design (RWD) MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/11/2016.
Sessions and cookies (part 2) MIS 3501, Fall 2015 Brad N Greenwood, PhD Department of MIS Fox School of Business Temple University 11/19/2015.
Introduction to AJAX MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/4/2016.
Sessions and cookies MIS 3501, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 4/12/2016.
National College of Science & Information Technology.
PDO Database Connections MIS 3501, Fall 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 3/8/2016.
Introduction to JavaScript MIS 3502, Fall 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 9/29/2016.
PDO Database Connections
Class03 Introduction to Web Development (Hierarchy and the IDE)
Brad N Greenwood, PhD MBA
Sessions and cookies MIS 3501 Jeremy Shafer Department of MIS
Form Data (part 2) MIS 3502, Fall 2015 Jeremy Shafer Department of MIS
Web Technologies Computing Science Thompson Rivers University
Introduction to Web Development (Part 2)
Data Virtualization Tutorial… CORS and CIS
PHP: includes MIS 3501 Jeremy Shafer Department of MIS
Sessions and cookies (part 2)
Form Data (part 1) MIS 3502, Fall 2015 Jeremy Shafer Department of MIS
AJAX.
PDO Database Connections
How to get data from a form
PHP Functions, Scope MIS 3501, Fall 2015 Jeremy Shafer
PDO Database Connections: Getting data out of the database
Introduction to AJAX MIS 3502 Jeremy Shafer Department of MIS
Introduction to JavaScript
Introduction to AJAX MIS 3502 Jeremy Shafer Department of MIS
PDO Database Connections: Getting data out of the database
Form Data (part 2) MIS 3501 Jeremy Shafer Department of MIS
A second look at JavaScript
Web Browser server client 3-Tier Architecture Apache web server PHP
Ajax and JSON (jQuery part 2)
PDO Database Connections
Organize your code with MVC
Sessions and cookies (part 1)
PDO Database Connections
Form Data (part 2) MIS 3501 Jeremy Shafer Department of MIS
Class05 How to get data from a form
JavaScript & jQuery AJAX.
MySQL Backup, Transfer and Restore
Secure Web Programming
Strings and Serialization
Sessions and cookies MIS 3501 Jeremy Shafer Department of MIS
MIS JavaScript and API Workshop (Part 3)
Introduction to AJAX and JSON
Programming Control Structures with JavaScript Part 2
Form Data (part 1) MIS3501 Jeremy Shafer Department of MIS
Introduction to JavaScript
An introduction to jQuery
Introduction to MIS3502 MIS 3502 Jeremy Shafer Department of MIS
MVC – Model View Controller
PDO and Arrays MIS 3502 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
Ajax and JSON Jeremy Shafer Department of MIS Fox School of Business
Presentation transcript:

JavaScript, AJAX and JSON MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/9/2016

Course Overview New tools Weeks Using a web framework Weeks 6 -8 Using a mobile device IDE Weeks 9-10 The class project (It’s a bake off!) Weeks We are (still) here Arrays PDO MVC JavaScript / JSON Slide 2

Overview So, what’s JSON? What is JSON good for? PHP’s json_encode Caching and the PHP header function Example: Using JSON to populate a menu Slide 3

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

JSON vs. XML A XML object looks like this: Slide 5

Where is JSON used? Database PHP Interpreter Browser JavaScript Engine HTTP Requests How is the data formatted? JSON? XML? Plain text? Slide 6

Why this is 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 Slide 7

Why this is a big deal… 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, Melonie, Lauren, William Uh oh! Dependent #4! Slide 8

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 Slide 9

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. Slide 10

PHP and json_encode() Do I have to render all that syntax myself? No. PHP provides us with a built in function called json_encode. json_encode will accept a PHP array or object as a parameter and return the JSON representation of that array or object. Slide 11

So why bother? Efficiency. When our systems grow to be large, we want to cut down on as much database traffic as possible. We want to put more processing burden on the client. Using a http “GET” to pull in resources we need allow us to manage aspects of our page that are not likely to change Slide 12

The PHP header function We can use the PHP header function to control the caching of of a page. Page caching is when a browser retains an off line copy of a page. Often we want to disable page caching. We can do that with the following code: header("Expires: Mon, 26 Jul :00:00 GMT"); header("Cache-Control: no-cache"); header("Pragma: no-cache"); Slide 13

The PHP header function header("Expires: Mon, 26 Jul :00:00 GMT"); This statement says, this page expired at some date in the past. header("Cache-Control: no-cache"); This statement says, the page needs to be validated every time it loads. It ensures that secure https pages can't be stored. header("Pragma: no-cache"); Isn't used that much anymore. It does the same sort of thing as Cache-control. Better safe than sorry. Slide 14

The PHP header function Sometimes we want to have caching take place. That’s easier, as it is the default behavior of most browsers. We can use “Expires” and specify a date in the future: header("Expires: Fri, 4 Feb :00:00 GMT"); Or… specify nothing at all. Slide 15

Summary So, what’s JSON? –JavaScript Object Notation What is JSON good for? –Data exchange PHP’s json_encode –Transforms a PHP array into JSON Caching and the PHP header function Example: Using JSON to populate a menu Slide 16

Time for an exercise! This is Jason Not JSON Slide 17