SlideShare a Scribd company logo
Your Requirement. Our Commitment.
Index No
AJAX - Introduction 01
XMLHttpRequest object 02
AJAX Request 03-04
AJAX – Get or Post 05
AJAX Response 06-08
Response from the web server 09
Callback function 10
JSON - Introduction 11
JSON - Advantages 12
JSON – XML Comparison 13-14
JSON - Syntax 15-16
JSON - Array 17
JSON - Object 18
JSON – Javascript 19
JSON - Parsing 20
AJAX
AJAX - Introduction
 Stands for Asynchronous JavaScript and XML
 The AJAX enables the asynchronous update of the web pages by exchanging data with the
server behind the scenes
 Set of techniques for creating highly interactive web sites and web applications.
 The standard example of application using AJAX is Google Maps.
01
XMLHttpRequest object
 XMLHttpRequest objects is a means of sending and receiving data from web server.
 Supported by most modern browsers
xmlHttp = new XMLHttpRequest();
 In case of earlier versions of Internet, you must use the following syntax
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
02
AJAX Request
 XMLHttpRequest object supports open() and send() methods to send AJAX request to server.
xmlHttp.open("GET","ajax_info.txt",true);
xmlHttp.send();
03
Method Description
open(method,url,async  Method : the type of request: GET or POST
 url : the location of the file on the server
 Async : true (asynchronous) or false (synchronous)
send(string) Sends the request off to the server.
string: Only used for POST requests
AJAX Request
 GET Requests:
xmlHttp.open("GET","ajax_info.txt",true);
xmlHttp.send();
 Post Requests:
xmlHttp.open("POST","demo.aspx",true);
xmlHttp.send();
 The file on the web server can essentially be any kind of file, such as .txt and .xml.
 Also, the file can even be server scripting files such as .aspx, .php, etc. that perform actions on
the server before sending the response back.
 The async parameter of the open() method can take both the true and false values, it is
recommended that it needs to be set to true.
04
AJAX – Get or Post
 Get() is faster compared to Post()
 Use Post() when your application:
 Does not require a cached file that is needed to update a file or database on the server.
 Demands you to send large amount of data to the server. This is due to the fact that POST
requests does not have any size limitations.
 Requires you to send user input that might contain unknown characters. This is because
POST requests is much more robust and secure as compares to GET requests.
05
AJAX Response
06
AJAX Response
07
xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange=function() {
if (xmlHttp.readyState==4 && xmlHttp.status==200) {
document.getElementById("productName").innerHTML=xmlhttp.responseText;
} }
xmlHttp.open("GET","demo.aspx",true);
xmlHttp.send();
Response from the web server
 Use the responseText property only when the response from the server is not XML.
document.getElementById("prodName").innerHTML=xmlhttp.responseText;
 Use the responseXML property when the response from the server is XML and parse it as a XML
object.
products= xmlHttp.responseXML;
x= products.getElementsByTagName(“movies");
document.getElementById(“movies").innerHTML= x;
08
Callback function
 The callback function can be defined as a function that is set as a parameter to another function.
09
function start() {
var xmlhttp = new XMLHttpRequest();
var contentDiv = document.getElementById(“addContent");
xmlhttp.open("POST", "Demo.xml", true);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
contentDiv.innerHTML=xmlhttp.responseText;
}
}
xmlhttp.send("FirstName=Nat&LastName=Dunn");
}
AJAX - Response
 AJAX can be used to retrieve plain text, HTML, XML or JSON data.
 Use the responseText to read text and JSON data • Use the responseXML to read XML data
 Let us look at examples to read following data using AJAX:
 Text
 HTML
 JSON
 XML
10
JSON
JSON - Introduction
 Stands for JavaScript Object Notation
 It is a format for data transfer
 It is derived from JavaScript
 It is language independent
 It is an alternative to XML
11
JSON - Advantages
 Lightweight text-data interchange format.
 Easy to parse JSON syntax
 Leaner than XML
 Ease in use as it is platform and language independent.
12
JSON – XML Comparison
 Both JSON and XML are data exchange formats, but the XML format is associated with a few
drawbacks as compared to JSON.
 The XML format contains roots in marking-up document text and operates well in that space.
 The JSON, on the other hand, possess roots in the programming language types and structures.
 As a result, JSON offers a natural and easily available mapping mechanism to exchange
structured data.
13
JSON – XML Comparison
 Comparing JSON to XML
14
Characteristic XML JSON
Data Types Does not provide any notion of data
types. One must rely on XML Schema for
adding type information.
Provides scalar data types and the ability to
express structured data through arrays and
objects.
Size Documents tend to be lengthy in size,
especially when an element-centric
approach to formatting is used.
Syntax is very terse and yields formatted text
where most of the space is consumed by the
represented data.
Parsing in JavaScript Requires an XML DOM implementation
and additional application code to map
text back into JavaScript objects.
No additional application code required to
parse text. It uses JavaScript's eval function.
JSON - Syntax
 Include data within name/value pairs.
 Separate the data appropriately by using commas.
 Normally, the JSON data can take any of the following values:
 A number which can either be an integer or floating point.
 A string that must be enclosed within in double quotes.
 A Boolean terminates to either true or false value.
 An array that must be enclosed within square brackets.
 An object that must be enclosed within in curly brackets.
 A null or empty value.
 Enclose the objects within curly braces.
 Enclose the arrays within square brackets.
15
JSON - Syntax
 JSON data consists of name/value pairs
 Field name is enclosed in double quotes
 Field names can contain spaces, -, special characters
16
{
"name" : “Tom Hanks“,
“DOB” : “July 9, 1956”,
“age” : 50,
“isAlive” : true,
“movies” : null
}
JSON - Array
 You must make sure to enclose the JSON arrays within square brackets.
17
{
“movies": [
{ "name":“Edge of Tomorrow" , “Actor":”Tom Cruise”},
{ "name":“How to Train Your Dragon" , “Actor":”Jay Baruchel” }
]
}
JSON - Object
 You must make sure to enclose the JSON objects within curly brackets as shown in the below
example.
18
Var movie = {
"name":“Edge of Tomorrow" ,
“Actor": {
“male” : ”Tom Cruise”,
“female” : “Emily Blunt”
}
}
JSON – Javascript
 The fact that the JSON makes use of the JavaScript syntax, the programmer does not require any
additional software to work with JSON within JavaScript.
19
var actor = {
"name" : “Tom Hanks“,
“DOB” : “July 9, 1956”
}
 Reading JSON values:
actor.name;
 Output:
Output : Tom Hanks
JSON - Parsing
 JSON data is easy to parse in all languages
 Use JavaScript function eval() to convert a JSON text into a JavaScript object.
 Make sure to include the text within parenthesis to avoid a syntax error as shown in the below
code snippet.
var actor = {
"name" : “Tom Hanks“,
“DOB” : “July 9, 1956”
}
var obj = eval ("(" + actor + ")");
 eval() is not a secure way of parsing JSON value. Instead use JSON.parse().
 However JSON.parse() is not supported in the older browsers.
 You can also use jQuery parseJSON() API to parse JSON values.
20
Mob : +91 98440 18630 / 99000 98630
Mail : enquiry@rsolutions-india.com
Url : www.rsolutions-india.com

More Related Content

What's hot (20)

ODP
Json Tutorial
Napendra Singh
 
PPTX
JSON
Zara Tariq
 
PDF
Rupy2012 ArangoDB Workshop Part1
ArangoDB Database
 
PDF
ElasticSearch
Volodymyr Kraietskyi
 
PDF
Odoo Technical Concepts Summary
Mohamed Magdy
 
PPTX
Mongo db
Ramakrishna kapa
 
PPTX
Opps Concept
F(x) Data Labs Pvt Ltd
 
PPTX
Mule: JSON to Object
Sulthony Hartanto
 
PDF
Getting started with MongoDB and Scala - Open Source Bridge 2012
sullis
 
PDF
EKAW - Publishing with Triple Pattern Fragments
Ruben Taelman
 
PDF
NyaruDBにゃるものを使ってみた話 (+Realm比較)
Masaki Oshikawa
 
PPT
Ajax
Manav Prasad
 
PDF
FOXX - a Javascript application framework on top of ArangoDB
ArangoDB Database
 
PDF
Dax Declarative Api For Xml
Lars Trieloff
 
PDF
Open source Technology
Amardeep Vishwakarma
 
PDF
Ajax chap 3
Mukesh Tekwani
 
PDF
Ajax chap 2.-part 1
Mukesh Tekwani
 
Json Tutorial
Napendra Singh
 
Rupy2012 ArangoDB Workshop Part1
ArangoDB Database
 
ElasticSearch
Volodymyr Kraietskyi
 
Odoo Technical Concepts Summary
Mohamed Magdy
 
Mule: JSON to Object
Sulthony Hartanto
 
Getting started with MongoDB and Scala - Open Source Bridge 2012
sullis
 
EKAW - Publishing with Triple Pattern Fragments
Ruben Taelman
 
NyaruDBにゃるものを使ってみた話 (+Realm比較)
Masaki Oshikawa
 
FOXX - a Javascript application framework on top of ArangoDB
ArangoDB Database
 
Dax Declarative Api For Xml
Lars Trieloff
 
Open source Technology
Amardeep Vishwakarma
 
Ajax chap 3
Mukesh Tekwani
 
Ajax chap 2.-part 1
Mukesh Tekwani
 

Similar to Web Development Course - AJAX & JSON by RSOLUTIONS (20)

PPTX
JSON & AJAX.pptx
dyumna2
 
PPTX
Web technologies-course 10.pptx
Stefan Oprea
 
PPTX
JSON
Yoga Raja
 
PPTX
AJAX and JSON
Julie Iskander
 
PPTX
Introduction to JSON & AJAX
Raveendra R
 
PPT
Json – java script object notation
Dilip Kumar Gupta
 
PPTX
Introduction to JavaScript Object Notation(JSON)
gaikwaddavid2022
 
PPT
Ajax
ch samaram
 
PPTX
HSHDGDGDHDYDUDUDUDHDHDHSHAHAHSHSBDHDHDHDHDHD
srlegaspi2101
 
PPTX
BITM3730Week6.pptx
MattMarino13
 
PPTX
javaScript and jQuery
Mehrab Hossain
 
PDF
AJAX - An introduction
Eleonora Ciceri
 
DOCX
Copy of ajax tutorial
Abhishek Kesharwani
 
PPT
AJAX
ankurgupta
 
PPTX
Data exchange over internet (XML vs JSON)
Wajahat Shahid
 
PPTX
HTML, Javascript and AJAX
Wan Leung Wong
 
PPTX
All about XML, JSON and related topics..
tinumanueltmt
 
PPTX
Ajax enabled rich internet applications with xml and json
ArchanaMani2
 
PPTX
Web-Engineering-Lec-14 (1) .pptx
iamayesha2526
 
JSON & AJAX.pptx
dyumna2
 
Web technologies-course 10.pptx
Stefan Oprea
 
JSON
Yoga Raja
 
AJAX and JSON
Julie Iskander
 
Introduction to JSON & AJAX
Raveendra R
 
Json – java script object notation
Dilip Kumar Gupta
 
Introduction to JavaScript Object Notation(JSON)
gaikwaddavid2022
 
HSHDGDGDHDYDUDUDUDHDHDHSHAHAHSHSBDHDHDHDHDHD
srlegaspi2101
 
BITM3730Week6.pptx
MattMarino13
 
javaScript and jQuery
Mehrab Hossain
 
AJAX - An introduction
Eleonora Ciceri
 
Copy of ajax tutorial
Abhishek Kesharwani
 
Data exchange over internet (XML vs JSON)
Wajahat Shahid
 
HTML, Javascript and AJAX
Wan Leung Wong
 
All about XML, JSON and related topics..
tinumanueltmt
 
Ajax enabled rich internet applications with xml and json
ArchanaMani2
 
Web-Engineering-Lec-14 (1) .pptx
iamayesha2526
 
Ad

More from RSolutions (9)

PPTX
MS SQL - Database Programming Concepts by RSolutions
RSolutions
 
PPTX
Web Development Course - XML by RSOLUTIONS
RSolutions
 
PPTX
Web Development Course - JQuery by RSOLUTIONS
RSolutions
 
PPTX
Web Development Course - Twitter Bootstrap by RSOLUTIONS
RSolutions
 
PPTX
Web Development Course - HTML5 & CSS3 by RSOLUTIONS
RSolutions
 
PDF
RLA Learning Book for Pre-Primary Kids
RSolutions
 
PPTX
RSolutions Products Deck 2020
RSolutions
 
PPTX
RSolutions Profile 2020
RSolutions
 
PPTX
RSolutions Complete Catalogue 2020
RSolutions
 
MS SQL - Database Programming Concepts by RSolutions
RSolutions
 
Web Development Course - XML by RSOLUTIONS
RSolutions
 
Web Development Course - JQuery by RSOLUTIONS
RSolutions
 
Web Development Course - Twitter Bootstrap by RSOLUTIONS
RSolutions
 
Web Development Course - HTML5 & CSS3 by RSOLUTIONS
RSolutions
 
RLA Learning Book for Pre-Primary Kids
RSolutions
 
RSolutions Products Deck 2020
RSolutions
 
RSolutions Profile 2020
RSolutions
 
RSolutions Complete Catalogue 2020
RSolutions
 
Ad

Recently uploaded (20)

PDF
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
PPTX
Controller Request and Response in Odoo18
Celine George
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PDF
Horarios de distribución de agua en julio
pegazohn1978
 
PPTX
infertility, types,causes, impact, and management
Ritu480198
 
PDF
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PDF
STATEMENT-BY-THE-HON.-MINISTER-FOR-HEALTH-ON-THE-COVID-19-OUTBREAK-AT-UG_revi...
nservice241
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PPTX
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
PPTX
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
PDF
Week 2 - Irish Natural Heritage Powerpoint.pdf
swainealan
 
PPTX
Introduction to Indian Writing in English
Trushali Dodiya
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PPTX
Difference between write and update in odoo 18
Celine George
 
PPTX
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
PDF
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
PDF
Introduction presentation of the patentbutler tool
MIPLM
 
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
Controller Request and Response in Odoo18
Celine George
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
Horarios de distribución de agua en julio
pegazohn1978
 
infertility, types,causes, impact, and management
Ritu480198
 
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
STATEMENT-BY-THE-HON.-MINISTER-FOR-HEALTH-ON-THE-COVID-19-OUTBREAK-AT-UG_revi...
nservice241
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
Week 2 - Irish Natural Heritage Powerpoint.pdf
swainealan
 
Introduction to Indian Writing in English
Trushali Dodiya
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
Difference between write and update in odoo 18
Celine George
 
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
Introduction presentation of the patentbutler tool
MIPLM
 

Web Development Course - AJAX & JSON by RSOLUTIONS

  • 1. Your Requirement. Our Commitment.
  • 2. Index No AJAX - Introduction 01 XMLHttpRequest object 02 AJAX Request 03-04 AJAX – Get or Post 05 AJAX Response 06-08 Response from the web server 09 Callback function 10 JSON - Introduction 11 JSON - Advantages 12 JSON – XML Comparison 13-14 JSON - Syntax 15-16 JSON - Array 17 JSON - Object 18 JSON – Javascript 19 JSON - Parsing 20
  • 4. AJAX - Introduction  Stands for Asynchronous JavaScript and XML  The AJAX enables the asynchronous update of the web pages by exchanging data with the server behind the scenes  Set of techniques for creating highly interactive web sites and web applications.  The standard example of application using AJAX is Google Maps. 01
  • 5. XMLHttpRequest object  XMLHttpRequest objects is a means of sending and receiving data from web server.  Supported by most modern browsers xmlHttp = new XMLHttpRequest();  In case of earlier versions of Internet, you must use the following syntax xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 02
  • 6. AJAX Request  XMLHttpRequest object supports open() and send() methods to send AJAX request to server. xmlHttp.open("GET","ajax_info.txt",true); xmlHttp.send(); 03 Method Description open(method,url,async  Method : the type of request: GET or POST  url : the location of the file on the server  Async : true (asynchronous) or false (synchronous) send(string) Sends the request off to the server. string: Only used for POST requests
  • 7. AJAX Request  GET Requests: xmlHttp.open("GET","ajax_info.txt",true); xmlHttp.send();  Post Requests: xmlHttp.open("POST","demo.aspx",true); xmlHttp.send();  The file on the web server can essentially be any kind of file, such as .txt and .xml.  Also, the file can even be server scripting files such as .aspx, .php, etc. that perform actions on the server before sending the response back.  The async parameter of the open() method can take both the true and false values, it is recommended that it needs to be set to true. 04
  • 8. AJAX – Get or Post  Get() is faster compared to Post()  Use Post() when your application:  Does not require a cached file that is needed to update a file or database on the server.  Demands you to send large amount of data to the server. This is due to the fact that POST requests does not have any size limitations.  Requires you to send user input that might contain unknown characters. This is because POST requests is much more robust and secure as compares to GET requests. 05
  • 10. AJAX Response 07 xmlHttp = new XMLHttpRequest(); xmlHttp.onreadystatechange=function() { if (xmlHttp.readyState==4 && xmlHttp.status==200) { document.getElementById("productName").innerHTML=xmlhttp.responseText; } } xmlHttp.open("GET","demo.aspx",true); xmlHttp.send();
  • 11. Response from the web server  Use the responseText property only when the response from the server is not XML. document.getElementById("prodName").innerHTML=xmlhttp.responseText;  Use the responseXML property when the response from the server is XML and parse it as a XML object. products= xmlHttp.responseXML; x= products.getElementsByTagName(“movies"); document.getElementById(“movies").innerHTML= x; 08
  • 12. Callback function  The callback function can be defined as a function that is set as a parameter to another function. 09 function start() { var xmlhttp = new XMLHttpRequest(); var contentDiv = document.getElementById(“addContent"); xmlhttp.open("POST", "Demo.xml", true); xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { contentDiv.innerHTML=xmlhttp.responseText; } } xmlhttp.send("FirstName=Nat&LastName=Dunn"); }
  • 13. AJAX - Response  AJAX can be used to retrieve plain text, HTML, XML or JSON data.  Use the responseText to read text and JSON data • Use the responseXML to read XML data  Let us look at examples to read following data using AJAX:  Text  HTML  JSON  XML 10
  • 14. JSON
  • 15. JSON - Introduction  Stands for JavaScript Object Notation  It is a format for data transfer  It is derived from JavaScript  It is language independent  It is an alternative to XML 11
  • 16. JSON - Advantages  Lightweight text-data interchange format.  Easy to parse JSON syntax  Leaner than XML  Ease in use as it is platform and language independent. 12
  • 17. JSON – XML Comparison  Both JSON and XML are data exchange formats, but the XML format is associated with a few drawbacks as compared to JSON.  The XML format contains roots in marking-up document text and operates well in that space.  The JSON, on the other hand, possess roots in the programming language types and structures.  As a result, JSON offers a natural and easily available mapping mechanism to exchange structured data. 13
  • 18. JSON – XML Comparison  Comparing JSON to XML 14 Characteristic XML JSON Data Types Does not provide any notion of data types. One must rely on XML Schema for adding type information. Provides scalar data types and the ability to express structured data through arrays and objects. Size Documents tend to be lengthy in size, especially when an element-centric approach to formatting is used. Syntax is very terse and yields formatted text where most of the space is consumed by the represented data. Parsing in JavaScript Requires an XML DOM implementation and additional application code to map text back into JavaScript objects. No additional application code required to parse text. It uses JavaScript's eval function.
  • 19. JSON - Syntax  Include data within name/value pairs.  Separate the data appropriately by using commas.  Normally, the JSON data can take any of the following values:  A number which can either be an integer or floating point.  A string that must be enclosed within in double quotes.  A Boolean terminates to either true or false value.  An array that must be enclosed within square brackets.  An object that must be enclosed within in curly brackets.  A null or empty value.  Enclose the objects within curly braces.  Enclose the arrays within square brackets. 15
  • 20. JSON - Syntax  JSON data consists of name/value pairs  Field name is enclosed in double quotes  Field names can contain spaces, -, special characters 16 { "name" : “Tom Hanks“, “DOB” : “July 9, 1956”, “age” : 50, “isAlive” : true, “movies” : null }
  • 21. JSON - Array  You must make sure to enclose the JSON arrays within square brackets. 17 { “movies": [ { "name":“Edge of Tomorrow" , “Actor":”Tom Cruise”}, { "name":“How to Train Your Dragon" , “Actor":”Jay Baruchel” } ] }
  • 22. JSON - Object  You must make sure to enclose the JSON objects within curly brackets as shown in the below example. 18 Var movie = { "name":“Edge of Tomorrow" , “Actor": { “male” : ”Tom Cruise”, “female” : “Emily Blunt” } }
  • 23. JSON – Javascript  The fact that the JSON makes use of the JavaScript syntax, the programmer does not require any additional software to work with JSON within JavaScript. 19 var actor = { "name" : “Tom Hanks“, “DOB” : “July 9, 1956” }  Reading JSON values: actor.name;  Output: Output : Tom Hanks
  • 24. JSON - Parsing  JSON data is easy to parse in all languages  Use JavaScript function eval() to convert a JSON text into a JavaScript object.  Make sure to include the text within parenthesis to avoid a syntax error as shown in the below code snippet. var actor = { "name" : “Tom Hanks“, “DOB” : “July 9, 1956” } var obj = eval ("(" + actor + ")");  eval() is not a secure way of parsing JSON value. Instead use JSON.parse().  However JSON.parse() is not supported in the older browsers.  You can also use jQuery parseJSON() API to parse JSON values. 20
  • 25. Mob : +91 98440 18630 / 99000 98630 Mail : [email protected] Url : www.rsolutions-india.com