SlideShare a Scribd company logo
1 of 17
Introduction to JSON & AJAX
www.collaborationtech.co.in
Bengaluru INDIA
Presentation By
Ramananda M.S Rao
JSON
Content
What is JSON ?
Where JSON is used ?
JSON Data Types and Values
Object
Arrays
Reading JSON data structure
Where JSON is used ?
Data Interchange
JSON vs. XML
JSON in AJAX
XMLHttpRequest
AJAX
POST and GET calls in AJAX
Ajax Methods and Properties
AJAX client Server Interactions
Benefits of Ajax
Current Issues of AJAX
JSONHttpRequest
JSON Limitations
About Us
www.collaborationtech.co.in
Introduction to JSON
What is JSON?
JSON stands for JavaScript Object Notation. JSON objects are used for
transferring data between server and client.
JSON is a subset of JavaScript. ( ECMA-262 ).
Language Independent, means it can work well with most of the modern
programming language
Text-based, human readable data exchange format
Light-weight. Easier to get and load the requested data quickly.
Easy to parse.
JSON has no version and No revisions to the JSON grammar.
JSON is very stable
Character Encoding is Strictly UNICODE. Default: UTF-8. Also UTF-16 and
UTF-32 are allowed.
official Internet media type for JSON is application/json.
JSON Is Not XML.
JSON is a simple, common representation of data.
www.collaborationtech.co.in
JSON DATA TYPES AND VALUES
JSON DATA TYPES AND VALUES
Strings
Numbers
Booleans
Objects
Arrays
null
www.collaborationtech.co.in
Object and Arrays
Object
 Objects are unordered containers of key/value pairs
 Objects are wrapped in { }
 , separates key/value pairs
 : separates keys and values
 Keys are strings
 Values are JSON values - struct,record,hashtable,object
Array
 Arrays are ordered sequences of values
 Arrays are wrapped in []
 , separates values
 An implementation can start array indexing at 0 or 1.
www.collaborationtech.co.in
JSON data:
JSON data: It basically has key-value pairs.
var chaitanya = {
"firstName" : "Chaitanya",
"lastName" : "Singh",
"age" : "28"
};
We can access the information out of a JSON object like this:
document.writeln("The name is: " +chaitanya.firstName);
document.writeln("his age is: " + chaitanya.age);
document.writeln("his last name is: "+ chaitanya.lastName);
www.collaborationtech.co.in
JSON data:
object with one member
{
"course-name": "6.470“
}
object with two members (separated by a comma)
{
"course 6 470"
course-name": "6.470",
"units": 6
}
array with 3 elements ["foo", "bar", 12345]
object with an array as a value
{
"course-name": "6.470",
"times": ["12-4","12-4", "12-4"]
}
www.collaborationtech.co.in
JSON data:
objects with objects and arrays
{
John : {
"label":"John",
"data":[[1880,0.081536],[1881,0.08098],[1882,0.078308]]
},
"James": {
"label":"James",
"data":[[1880,0.050053],[1881,0.05025],[1882,0.048278]]
}
}
var a = {
"John":
{
"label":"John",
"data":[[1880,0.081536],[1881,0.08098],[1882,0.078308]]
},
"James":
{
"label":"James",
"data":[[1880,0.050053],[1881,0.05025],[1882,0.048278]]
}
}
www.collaborationtech.co.in
Parsing JSON
To get the value 1880 marked with red color:
o We can use a.John.data[0][0]
JSON.stringify(): Takes a JavaScript object and produces a JSON string from it.
JSON.parse(): Takes a JSON string and parses it to a JavaScript object.
Parsing JSON in JavaScript
Start with a basic JSON string:
var json = '{ "person" : { "age" : 20, "name" : "Jack" } }';
Right now, all JavaScript sees here is a string. It doesn’t know it’s actually JSON. You can
pass it through to JSON.parse() to convert it into a JavaScript object:
var parsed = JSON.parse(json);
console.log(parsed);
This gives you:
{ person: { age: 20, name: 'Jack' } }
It is now a regular JavaScript object and you can access properties, just as you’d expect,
using either notation:
console.log(parsed.person);
console.log(parsed.person["age"]);
www.collaborationtech.co.in
Parsing JSON
You can do the opposite and turn an object into a string:
var json = {
person: {
age: 20,
name: "Jack"
}
}
console.log(JSON.stringify(json));
This gives you a string containing the following:
{"person":{"age":20,"name":"Jack"}}
www.collaborationtech.co.in
Reading JSON data structure
Simple JSON Example
<!DOCTYPE html>
<html>
<body>
<h2>JSON Object Creation in JavaScript</h2>
<p id="demo"></p>
<script>
var text = '{"name":"John Johnson","street":"Oslo West 16","phone":"555 1234567"}';
var obj = JSON.parse(text);
document.getElementById("demo").innerHTML = obj.name + "<br>" + obj.street + "<br>" +
obj.phone;
</script>
</body>
</html>
www.collaborationtech.co.in
AJAX
AJAX, or Asynchronous JavaScript and XML.
 Describes a Web development technique for creating interactive
Web applications using a combination of HTML (or XHTML) and
Cascading Style Sheets for presenting information; Document
Object Model (DOM).
 JavaScript, to dynamically display and interact with the information
presented; and the XMLHttpRequest object to interchange and
manipulate data asynchronously with the Web server.
 It allows for asynchronous communication, Instead of freezing up
until the completeness, the browser can communicate with server
and continue as normal.
www.collaborationtech.co.in
POST and GET calls in AJAX
POST and GET calls in AJAX
GET places arguments in the query string, but POST doesn’t.
No noticeable difference in AJAX - AJAX request does not appear
in the address bar.
GET call in AJAX still has the size limitation on the amount of
data that can be passed.
General principle:
GET method: it is used to retrieve data to display in the page
and the data is not expected to be changed on the server.
POST method: it is used to update information on the server
www.collaborationtech.co.in
Ajax Methods and Properties
Ajax Methods and Properties
Abort() : Aborts the request if it has already been sent.
getAllResponseHeaders() : Returns all the response headers as a string..
getResponseHeader("headerLabel") : Returns the text of a specified
header.
open("method", "URL"[,asyncFlag[, "userName"[,"password"]]]) :
Initializes a request. This method is to be used from JavaScript code;
to initialize a request from native code, use openRequest() instead.
send(content) :Sends the request. If the request is asynchronous (which is
thedefault), this method returns as soon as the request is sent. If the
( ) request is synchronous, this method doesn't return until the response
has arrived.
setRequestHeader("label", "value") : Sets the value of an HTTP request
header
www.collaborationtech.co.in
Example
<!DOCTYPE html>
<head><title>Ajax Test</title>
<script type="text/javascript">
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", "hello.txt", true);
xmlHttp.addEventListener("load", ajaxCallback, false);
xmlHttp.send(null);
function ajaxCallback(event){
alert( "Your file contains the text: " + event.target.responseText );
}
</script>
</head>
<body>
</body>
</html>
www.collaborationtech.co.in
Follow us on Social
Facebook: https://www.facebook.com/collaborationtechnologies/
Twitter : https://twitter.com/collaboration09
Google Plus : https://plus.google.com/100704494006819853579
LinkedIn : https://www.linkedin.com/in/ramananda-rao-a2012545
Instagram : https://instagram.com/collaborationtechnologies
YouTube :
https://www.youtube.com/channel/UCm9nK56LRbWSqcYWbzs8CUg
Skype : facebook:ramananda.rao.7
WhatsApp : +91 9886272445
www.collaborationtech.co.in
THANK YOU
About Us

More Related Content

What's hot

Character generation
Character generationCharacter generation
Character generation
Ankit Garg
 
Introduction To Single Page Application
Introduction To Single Page ApplicationIntroduction To Single Page Application
Introduction To Single Page Application
KMS Technology
 

What's hot (20)

How To be a Backend developer
How To be a Backend developer    How To be a Backend developer
How To be a Backend developer
 
Angularjs PPT
Angularjs PPTAngularjs PPT
Angularjs PPT
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
 
JSON: The Basics
JSON: The BasicsJSON: The Basics
JSON: The Basics
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
 
Angular App Presentation
Angular App PresentationAngular App Presentation
Angular App Presentation
 
Character generation
Character generationCharacter generation
Character generation
 
Model View Controller (MVC)
Model View Controller (MVC)Model View Controller (MVC)
Model View Controller (MVC)
 
Graphql usage
Graphql usageGraphql usage
Graphql usage
 
Jetpack Compose beginner.pdf
Jetpack Compose beginner.pdfJetpack Compose beginner.pdf
Jetpack Compose beginner.pdf
 
Java script
Java scriptJava script
Java script
 
Introduction of Html/css/js
Introduction of Html/css/jsIntroduction of Html/css/js
Introduction of Html/css/js
 
Introduction to back-end
Introduction to back-endIntroduction to back-end
Introduction to back-end
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
ReactJS presentation.pptx
ReactJS presentation.pptxReactJS presentation.pptx
ReactJS presentation.pptx
 
Ajax and Jquery
Ajax and JqueryAjax and Jquery
Ajax and Jquery
 
Ajax
AjaxAjax
Ajax
 
Introduction To Single Page Application
Introduction To Single Page ApplicationIntroduction To Single Page Application
Introduction To Single Page Application
 
JavaScript - Chapter 1 - Problem Solving
 JavaScript - Chapter 1 - Problem Solving JavaScript - Chapter 1 - Problem Solving
JavaScript - Chapter 1 - Problem Solving
 
Collections Framework
Collections FrameworkCollections Framework
Collections Framework
 

Viewers also liked

External Data Access with jQuery
External Data Access with jQueryExternal Data Access with jQuery
External Data Access with jQuery
Doncho Minkov
 
Simplify AJAX using jQuery
Simplify AJAX using jQuerySimplify AJAX using jQuery
Simplify AJAX using jQuery
Siva Arunachalam
 

Viewers also liked (20)

Introduction to JSON
Introduction to JSONIntroduction to JSON
Introduction to JSON
 
External Data Access with jQuery
External Data Access with jQueryExternal Data Access with jQuery
External Data Access with jQuery
 
Preprocessor CSS: SASS
Preprocessor CSS: SASSPreprocessor CSS: SASS
Preprocessor CSS: SASS
 
'Less' css
'Less' css'Less' css
'Less' css
 
Ajax xml json
Ajax xml jsonAjax xml json
Ajax xml json
 
JSON and AJAX JumpStart
JSON and AJAX JumpStartJSON and AJAX JumpStart
JSON and AJAX JumpStart
 
AJAX and JSON
AJAX and JSONAJAX and JSON
AJAX and JSON
 
Dynamic webpages using AJAX & JSON
Dynamic webpages using AJAX & JSONDynamic webpages using AJAX & JSON
Dynamic webpages using AJAX & JSON
 
Simplify AJAX using jQuery
Simplify AJAX using jQuerySimplify AJAX using jQuery
Simplify AJAX using jQuery
 
Careers In Java Script Ajax - Java Script Ajax Tutorials & Programs by Learni...
Careers In Java Script Ajax - Java Script Ajax Tutorials & Programs by Learni...Careers In Java Script Ajax - Java Script Ajax Tutorials & Programs by Learni...
Careers In Java Script Ajax - Java Script Ajax Tutorials & Programs by Learni...
 
Inner core of Ajax
Inner core of Ajax Inner core of Ajax
Inner core of Ajax
 
Hari Resume
Hari ResumeHari Resume
Hari Resume
 
Ajax by Examples 2
Ajax by Examples 2Ajax by Examples 2
Ajax by Examples 2
 
Json
JsonJson
Json
 
JSON
JSONJSON
JSON
 
Introduction to JavaScript Programming
Introduction to JavaScript ProgrammingIntroduction to JavaScript Programming
Introduction to JavaScript Programming
 
08 ajax
08 ajax08 ajax
08 ajax
 
Rekayasa web part 3 khaerul anwar
Rekayasa web part 3 khaerul anwarRekayasa web part 3 khaerul anwar
Rekayasa web part 3 khaerul anwar
 
An Introduction to the DOM
An Introduction to the DOMAn Introduction to the DOM
An Introduction to the DOM
 
When Ajax Attacks! Web application security fundamentals
When Ajax Attacks! Web application security fundamentalsWhen Ajax Attacks! Web application security fundamentals
When Ajax Attacks! Web application security fundamentals
 

Similar to Introduction to JSON & AJAX

Java Script Based Client Server Webapps 2
Java Script Based Client Server Webapps 2Java Script Based Client Server Webapps 2
Java Script Based Client Server Webapps 2
kriszyp
 
JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)
Talha Ocakçı
 
Ajax Presentation
Ajax PresentationAjax Presentation
Ajax Presentation
ronaldmam
 

Similar to Introduction to JSON & AJAX (20)

Introduction to JSON & AJAX
Introduction to JSON & AJAXIntroduction to JSON & AJAX
Introduction to JSON & AJAX
 
Java Script Based Client Server Webapps 2
Java Script Based Client Server Webapps 2Java Script Based Client Server Webapps 2
Java Script Based Client Server Webapps 2
 
Ajax
AjaxAjax
Ajax
 
Web Development Course - AJAX & JSON by RSOLUTIONS
Web Development Course - AJAX & JSON by RSOLUTIONSWeb Development Course - AJAX & JSON by RSOLUTIONS
Web Development Course - AJAX & JSON by RSOLUTIONS
 
Json
Json Json
Json
 
Basics of JSON (JavaScript Object Notation) with examples
Basics of JSON (JavaScript Object Notation) with examplesBasics of JSON (JavaScript Object Notation) with examples
Basics of JSON (JavaScript Object Notation) with examples
 
Json tutorial, a beguiner guide
Json tutorial, a beguiner guideJson tutorial, a beguiner guide
Json tutorial, a beguiner guide
 
Data models in Angular 1 & 2
Data models in Angular 1 & 2Data models in Angular 1 & 2
Data models in Angular 1 & 2
 
Mashup
MashupMashup
Mashup
 
Json
JsonJson
Json
 
Copy of ajax tutorial
Copy of ajax tutorialCopy of ajax tutorial
Copy of ajax tutorial
 
Json – java script object notation
Json – java script object notationJson – java script object notation
Json – java script object notation
 
Advanced Json
Advanced JsonAdvanced Json
Advanced Json
 
Node js crash course session 5
Node js crash course   session 5Node js crash course   session 5
Node js crash course session 5
 
Ajax Introduction
Ajax IntroductionAjax Introduction
Ajax Introduction
 
JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)
 
Ajax Presentation
Ajax PresentationAjax Presentation
Ajax Presentation
 
Web technologies-course 10.pptx
Web technologies-course 10.pptxWeb technologies-course 10.pptx
Web technologies-course 10.pptx
 
Lec 7
Lec 7Lec 7
Lec 7
 
Json
JsonJson
Json
 

More from Collaboration Technologies

More from Collaboration Technologies (16)

Introduction to Core Java Programming
Introduction to Core Java ProgrammingIntroduction to Core Java Programming
Introduction to Core Java Programming
 
Introduction to Database SQL & PL/SQL
Introduction to Database SQL & PL/SQLIntroduction to Database SQL & PL/SQL
Introduction to Database SQL & PL/SQL
 
Introduction to Advanced Javascript
Introduction to Advanced JavascriptIntroduction to Advanced Javascript
Introduction to Advanced Javascript
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
Introduction to Bootstrap
Introduction to BootstrapIntroduction to Bootstrap
Introduction to Bootstrap
 
Introduction to Hibernate Framework
Introduction to Hibernate FrameworkIntroduction to Hibernate Framework
Introduction to Hibernate Framework
 
Introduction to HTML4
Introduction to HTML4Introduction to HTML4
Introduction to HTML4
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5
 
Introduction to JPA Framework
Introduction to JPA FrameworkIntroduction to JPA Framework
Introduction to JPA Framework
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Introduction to Perl Programming
Introduction to Perl ProgrammingIntroduction to Perl Programming
Introduction to Perl Programming
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Introduction to Python Basics Programming
Introduction to Python Basics ProgrammingIntroduction to Python Basics Programming
Introduction to Python Basics Programming
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Introduction to Struts 2
Introduction to Struts 2Introduction to Struts 2
Introduction to Struts 2
 
Introduction to Node.JS
Introduction to Node.JSIntroduction to Node.JS
Introduction to Node.JS
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 

Introduction to JSON & AJAX

  • 1. Introduction to JSON & AJAX www.collaborationtech.co.in Bengaluru INDIA Presentation By Ramananda M.S Rao
  • 2. JSON Content What is JSON ? Where JSON is used ? JSON Data Types and Values Object Arrays Reading JSON data structure Where JSON is used ? Data Interchange JSON vs. XML JSON in AJAX XMLHttpRequest AJAX POST and GET calls in AJAX Ajax Methods and Properties AJAX client Server Interactions Benefits of Ajax Current Issues of AJAX JSONHttpRequest JSON Limitations About Us www.collaborationtech.co.in
  • 3. Introduction to JSON What is JSON? JSON stands for JavaScript Object Notation. JSON objects are used for transferring data between server and client. JSON is a subset of JavaScript. ( ECMA-262 ). Language Independent, means it can work well with most of the modern programming language Text-based, human readable data exchange format Light-weight. Easier to get and load the requested data quickly. Easy to parse. JSON has no version and No revisions to the JSON grammar. JSON is very stable Character Encoding is Strictly UNICODE. Default: UTF-8. Also UTF-16 and UTF-32 are allowed. official Internet media type for JSON is application/json. JSON Is Not XML. JSON is a simple, common representation of data. www.collaborationtech.co.in
  • 4. JSON DATA TYPES AND VALUES JSON DATA TYPES AND VALUES Strings Numbers Booleans Objects Arrays null www.collaborationtech.co.in
  • 5. Object and Arrays Object  Objects are unordered containers of key/value pairs  Objects are wrapped in { }  , separates key/value pairs  : separates keys and values  Keys are strings  Values are JSON values - struct,record,hashtable,object Array  Arrays are ordered sequences of values  Arrays are wrapped in []  , separates values  An implementation can start array indexing at 0 or 1. www.collaborationtech.co.in
  • 6. JSON data: JSON data: It basically has key-value pairs. var chaitanya = { "firstName" : "Chaitanya", "lastName" : "Singh", "age" : "28" }; We can access the information out of a JSON object like this: document.writeln("The name is: " +chaitanya.firstName); document.writeln("his age is: " + chaitanya.age); document.writeln("his last name is: "+ chaitanya.lastName); www.collaborationtech.co.in
  • 7. JSON data: object with one member { "course-name": "6.470“ } object with two members (separated by a comma) { "course 6 470" course-name": "6.470", "units": 6 } array with 3 elements ["foo", "bar", 12345] object with an array as a value { "course-name": "6.470", "times": ["12-4","12-4", "12-4"] } www.collaborationtech.co.in
  • 8. JSON data: objects with objects and arrays { John : { "label":"John", "data":[[1880,0.081536],[1881,0.08098],[1882,0.078308]] }, "James": { "label":"James", "data":[[1880,0.050053],[1881,0.05025],[1882,0.048278]] } } var a = { "John": { "label":"John", "data":[[1880,0.081536],[1881,0.08098],[1882,0.078308]] }, "James": { "label":"James", "data":[[1880,0.050053],[1881,0.05025],[1882,0.048278]] } } www.collaborationtech.co.in
  • 9. Parsing JSON To get the value 1880 marked with red color: o We can use a.John.data[0][0] JSON.stringify(): Takes a JavaScript object and produces a JSON string from it. JSON.parse(): Takes a JSON string and parses it to a JavaScript object. Parsing JSON in JavaScript Start with a basic JSON string: var json = '{ "person" : { "age" : 20, "name" : "Jack" } }'; Right now, all JavaScript sees here is a string. It doesn’t know it’s actually JSON. You can pass it through to JSON.parse() to convert it into a JavaScript object: var parsed = JSON.parse(json); console.log(parsed); This gives you: { person: { age: 20, name: 'Jack' } } It is now a regular JavaScript object and you can access properties, just as you’d expect, using either notation: console.log(parsed.person); console.log(parsed.person["age"]); www.collaborationtech.co.in
  • 10. Parsing JSON You can do the opposite and turn an object into a string: var json = { person: { age: 20, name: "Jack" } } console.log(JSON.stringify(json)); This gives you a string containing the following: {"person":{"age":20,"name":"Jack"}} www.collaborationtech.co.in
  • 11. Reading JSON data structure Simple JSON Example <!DOCTYPE html> <html> <body> <h2>JSON Object Creation in JavaScript</h2> <p id="demo"></p> <script> var text = '{"name":"John Johnson","street":"Oslo West 16","phone":"555 1234567"}'; var obj = JSON.parse(text); document.getElementById("demo").innerHTML = obj.name + "<br>" + obj.street + "<br>" + obj.phone; </script> </body> </html> www.collaborationtech.co.in
  • 12. AJAX AJAX, or Asynchronous JavaScript and XML.  Describes a Web development technique for creating interactive Web applications using a combination of HTML (or XHTML) and Cascading Style Sheets for presenting information; Document Object Model (DOM).  JavaScript, to dynamically display and interact with the information presented; and the XMLHttpRequest object to interchange and manipulate data asynchronously with the Web server.  It allows for asynchronous communication, Instead of freezing up until the completeness, the browser can communicate with server and continue as normal. www.collaborationtech.co.in
  • 13. POST and GET calls in AJAX POST and GET calls in AJAX GET places arguments in the query string, but POST doesn’t. No noticeable difference in AJAX - AJAX request does not appear in the address bar. GET call in AJAX still has the size limitation on the amount of data that can be passed. General principle: GET method: it is used to retrieve data to display in the page and the data is not expected to be changed on the server. POST method: it is used to update information on the server www.collaborationtech.co.in
  • 14. Ajax Methods and Properties Ajax Methods and Properties Abort() : Aborts the request if it has already been sent. getAllResponseHeaders() : Returns all the response headers as a string.. getResponseHeader("headerLabel") : Returns the text of a specified header. open("method", "URL"[,asyncFlag[, "userName"[,"password"]]]) : Initializes a request. This method is to be used from JavaScript code; to initialize a request from native code, use openRequest() instead. send(content) :Sends the request. If the request is asynchronous (which is thedefault), this method returns as soon as the request is sent. If the ( ) request is synchronous, this method doesn't return until the response has arrived. setRequestHeader("label", "value") : Sets the value of an HTTP request header www.collaborationtech.co.in
  • 15. Example <!DOCTYPE html> <head><title>Ajax Test</title> <script type="text/javascript"> var xmlHttp = new XMLHttpRequest(); xmlHttp.open("GET", "hello.txt", true); xmlHttp.addEventListener("load", ajaxCallback, false); xmlHttp.send(null); function ajaxCallback(event){ alert( "Your file contains the text: " + event.target.responseText ); } </script> </head> <body> </body> </html> www.collaborationtech.co.in
  • 16. Follow us on Social Facebook: https://www.facebook.com/collaborationtechnologies/ Twitter : https://twitter.com/collaboration09 Google Plus : https://plus.google.com/100704494006819853579 LinkedIn : https://www.linkedin.com/in/ramananda-rao-a2012545 Instagram : https://instagram.com/collaborationtechnologies YouTube : https://www.youtube.com/channel/UCm9nK56LRbWSqcYWbzs8CUg Skype : facebook:ramananda.rao.7 WhatsApp : +91 9886272445 www.collaborationtech.co.in THANK YOU