Storing Data.

Slides:



Advertisements
Similar presentations
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming cookies.
Advertisements

JavaScript Forms Form Validation Cookies. What JavaScript can do  Control document appearance and content  Control the browser  Interact with user.
JSON Valery Ivanov.
JSON IDU0075 Sissejuhatus veebiteenustesse.  JSON stands for JavaScript Object Notation  JSON is lightweight text-data interchange format  JSON is.
Web Storage IDIA 619 Spring 2013 Bridget M. Blodgett.
15-Jul-15 JSON. JSON example “JSON” stands for “JavaScript Object Notation” Despite the name, JSON is a (mostly) language-independent way of specifying.
Chapter 25 Utilizing Web Storage.
Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh University.
Working with Cookies Managing Data in a Web Site Using JavaScript Cookies* *Check and comply with the current legislation regarding handling cookies.
Week 9 PHP Cookies and Session Introduction to JavaScript.
RESTful applications Norman White. REST Representational state transfer Key concepts – Client Server architecture built on transferring resources between.
Chapter 8 Cookies And Security JavaScript, Third Edition.
Introduction to JavaScript Gordon Tian
CHAP 6. USING THE HTML5 WEB STORAGE API.  Cookie - Are a built-in way of sending text values back and forth from server to client.  Servers can use.
Regular Expression (continue) and Cookies. Quick Review What letter values would be included for the following variable, which will be used for validation.
Introduction to HTML. What is HTML?  Hyper Text Markup Language  Not a programming language but a markup language  Used for presentation and layout.
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 Java Script Object Notation Copyright © 2013 Curt Hill.
Creating Dynamic Webpages
ECMM6018 Enterprise Networking for Electronic Commerce Tutorial 7
Persistence Maintaining state using cookies and queries.
HTML 5 Tutorial Chapter 6 Web Storage. Storing Data on The Client HTML5 offers two new objects for storing data on the client: localStorage - stores data.
CS2550 Dr. Brian Durney. SOURCES  JavaScript: The Definitive Guide, by David Flanagan  Dive into HTML5, by Mark Pilgrim
JSON – Java Script Object Notation. What is JSON JSON is a data interchange format Interactive Web 2.0 applications, no more use page replacement. Data.
Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Fundamentals of Web DevelopmentRandy.
Web Technologies Lecture 6 State preservation. Motivation How to keep user data while navigating on a website? – Authenticate only once – Store wish list.
PHP and Sessions. Session – a general definition The GENERAL definition of a session in the “COMPUTER WORLD” is: The interactions (requests and responses)
AJAX. Ajax  $.get  $.post  $.getJSON  $.ajax  json and xml  Looping over data results, success and error callbacks.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
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.
OVERVIEW AND PARSING JSON. What is JSON JavaScript Object Notation Used to format data Commonly used in Web as a vehicle to describe data being sent between.
Project 5: Customizing User Content Essentials for Design JavaScript Level Two Michael Brooks.
Presented By Nanda Kumar(972789) P. Trinesh (982816) Sk. Salma (982824) K. Madhuri (982814) HTML5.
JSON. JSON as an XML Alternative JSON is a light-weight alternative to XML for data- interchange JSON = JavaScript Object Notation It’s really language.
JSON (Copied from and from Prof Da Silva) Week 12 Web site:
11 jQuery Web Service Client. 22 Objectives You will be able to Use JSON (JavaScript Object Notation) for communcations between browser and server methods.
Web Storage and Cookies Cookies, Local and Session Storage SoftUni Team Technical Trainers Software University
WELCOME MIDHUN SUDHAKAR twitter.com/midhunopus in.linkedin.com/pub/midhunsudhakar/86/a65/a9.
XHTML. What Is XHTML? XHTML stands for EXtensible HyperText Markup Language XHTML is almost identical to HTML XHTML is stricter than HTML XHTML is HTML.
Framework and Graph Visualization Tools
The Fat-Free Alternative to XML
Creating Databases Local storage. join & split
The Fat-Free Alternative to XML
JSON.
19.10 Using Cookies A cookie is a piece of information that’s stored by a server in a text file on a client’s computer to maintain information about.
Exporting and Importing Data
Exporting and Importing Data
Database Systems Week 12 by Zohaib Jan.
Scope, Objects, Strings, Numbers
Consuming Java Script Object Notation (JSON) feeds
Cookies and JavaScript
Session V HTML5 APIs - AJAX & JSON
JavaScript an introduction.
Advanced Topics in Concurrency and Reactive Programming: MEAN Stack
Built in Fairfield County: Front End Developers Meetup
HTML Level II (CyberAdvantage)
HTML5 AJAX & JSON APIs
2017, Fall Pusan National University Ki-Joune Li
Session Tracking Techniques
JavaScript & jQuery AJAX.
HTML5 and Local Storage.
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
Integrating REST API and SQL Server JSON Functions
HTML5 and Local Storage.
The Fat-Free Alternative to XML
Both XML ad JSON are designed to transport data
PHP-II.
PHP and JSON Topics Review JSON.
JSON: JavaScript Object Notation
Web Client Side Technologies Raneem Qaddoura
Presentation transcript:

Storing Data

Local Storage With local storage, web applications can store data locally within the user's browser. Before HTML5, application data had to be stored in cookies, included in every server request. Local storage is more secure, and large amounts of data can be stored locally, without affecting website performance. Unlike cookies, the storage limit is far larger (at least 5MB) and information is never transferred to the server. Local storage is per origin (per domain and protocol). All pages, from one origin, can store and access the same data.

HTML Local Storage Objects HTML local storage provides two objects for storing data on the client: window.localStorage - stores data with no expiration date window.sessionStorage - stores data for one session (data is lost when the browser tab is closed)

Testing if (typeof(Storage) !== "undefined") { // Code for // localStorage/sessionStorage. } else { // Sorry! No Web Storage support.. }

The localStorage Object The localStorage object stores the data with no expiration date. The data will not be deleted when the browser is closed. // Store localStorage.setItem("lastname", "Smith"); // Retrieve var lastname=localStorage.getItem("lastname");

The previous example could have been written like this: // Store localStorage.lastname = "Smith"; // Retrieve var lastname= localStorage.lastname;

Removing localStorage.removeItem("lastname");

Note: Name/value pairs are always stored as strings Note: Name/value pairs are always stored as strings. Remember to convert them to another format as needed. Number(localStorage.quantity)

The sessionStorage Object The sessionStorage object is equal to the localStorage object, except that it stores the data for only one session. The data is deleted when the user closes the specific browser tab.

JSON JSON is a format for storing and transporting data. JSON is often used when data is sent from a server to a web page.

What is JSON? JSON stands for JavaScript Object Notation JSON is lightweight data interchange format JSON is language independent * JSON is "self-describing" and easy to understand * The JSON syntax is derived from JavaScript object notation syntax, but the JSON format is text only. Code for reading and generating JSON data can be written in any programming language.

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

The JSON Format Evaluates to JavaScript Objects

JSON Syntax Rules Data is in name/value pairs Data is separated by commas Curly braces hold objects Square brackets hold arrays { "employees":[     {"firstName":"John", "lastName":"Doe"},      {"firstName":"Anna", "lastName":"Smith"},     {"firstName":"Peter", "lastName":"Jones"} ] }

JSON Data - A Name and a Value JSON data is written as name/value pairs, just like JavaScript object properties. A name/value pair consists of a field name (in double quotes), followed by a colon, followed by a value: "firstName":"John"

JSON Objects JSON objects are written inside curly braces. Just like in JavaScript, objects can contain multiple name/value pairs: {"firstName":"John", "lastName":"Doe"}

JSON Arrays JSON arrays are written inside square brackets. Just like in JavaScript, an array can contain objects: "employees":[     {"firstName":"John", "lastName":"Doe"},      {"firstName":"Anna", "lastName":"Smith"},      {"firstName":"Peter", "lastName":"Jones"} ] In the example above, the object "employees" is an array. It contains three objects. Each object is a record of a person (with a first name and a last name).

Converting a JSON Text to a JavaScript Object A common use of JSON is to read data from a web server, and display the data in a web page. For simplicity, this can be demonstrated using a string as input. First, create a JavaScript string containing JSON syntax: var text = '{ "employees" : [' + '{ "firstName":"John" , "lastName":"Doe" },' + '{ "firstName":"Anna" , "lastName":"Smith" },' + '{ "firstName":"Peter" , "lastName":"Jones" } ]}';

Then, use the JavaScript built-in function JSON Then, use the JavaScript built-in function JSON.parse() to convert the string into a JavaScript object: var obj = JSON.parse(text); document.write(obj.employees[1].firstName + " " + obj.employees[1].lastName);

Sending Data If you have data stored in a JavaScript object, you can convert the object into JSON, and send it to a server: var myObj = { "name":"Jonny", "age":30, "city":"New York" }; var myJSON = JSON.stringify(myObj); window.location = "demo_json.php?x=" + myJSON;

Receiving Data If you receive data in JSON format, you can convert it into a JavaScript object: var myJSON = '{ "name":"John", "age":30, "city":"New York" }'; var myObj = JSON.parse(myJSON); document.write(myObj.name);

Storing Data //Storing data: myObj = { "name":"John", "age":30, "city":"New York" }; myJSON = JSON.stringify(myObj); localStorage.setItem("testJSON", myJSON); //Retrieving data: text = localStorage.getItem("testJSON"); obj = JSON.parse(text); document.write(obj.name);