SlideShare a Scribd company logo
AJAX.
XML and JSON
Andrii Siusko
October 2013
AGENDA
What is AJAX? Why do we need it?
HTMLRequest object
Data formats
– XML
• structure and syntax
• basic rules and restrictions
• best practices of use
– JSON
• YAML principles and structure
• basic rules
• best practices
PREREQUISITE
SO WHAT’S THE PROBLEM?
user must wait while new
pages load
POSSIBLE SOLUTION
user can keep interacting
with page while data loads
ASYNCHRONOUS WEB COMMUNICATION
WHAT IS AJAX?
AJAX : Asynchronous JavaScript and XML
 not a programming language; a particular way of using JavaScript
 downloads data from a server in the background
 allows dynamically updating a page without making the user wait
 avoids the "click-wait-refresh" pattern
AJAX is based on internet standards, and uses a combination of:
 XMLHttpRequest object (to exchange data asynchronously with a
server)
 JavaScript/DOM (to display/interact with the information)
 CSS (to style the data)
 XML (often used as the format for transferring data)
COMMUNICATION IN BACKGROUND –
HOW IS IT MADE?
Prerequisite: JavaScript
Create HTTPRequest object
Prepare data to send
Do .send() method
Watch for request status:
– not ok:
• fulfill error handling
– ok: 
• get server reply
• manage it
HTTPREQUEST OBJECT: CREATE
if (window.XMLHttpRequest){
// code for IE7+, Firefox, Chrome, Opera, Safari
ajax = new XMLHttpRequest();
}
else{
// code for IE6, IE5
ajax = new ActiveXObject("Microsoft.XMLHTTP");
}
HTTPREQUEST OBJECT:
HANDLE (METHODS)
.open(method, URL, async,
[userName], [password]);
• method = “GET” || “POST”;
• boolean async;
.send([content]);
.abort();
.getAllResponseHeaders();
• returns all headers as String;
.getResponseHeader(headerName);
• returns all headers as String;
HTTPREQUEST OBJECT:
HANDLE (FIELD)
.onreadystatechange = function {};
• describes what should script do on server response
.readyState
• 0 not initialized; 1 open;
• 2 sending…; 3 receiving…;
• 4 ready
.status; .statusText;
• 200 ok; 404 not found;
• 403 not authorized; …
.responseText; .responseXML
• responseXML could be parsed as DOM element
XMLHTTPREQUEST SECURITY
RESTRICTIONS
• cannot be run from a web page stored on
your hard drive
• can only be run on a web page stored on a
web server
• can only fetch files from the same site
that the page is on*
* 1. <script type="text/javascript“
src=“external_domein“ ></script>
2. Create XDR object:
xdr = new XDomainRequest(); // IE8+
3. easyXDM (Javascript library)
GOT REPLY. WHAT’S NOW?
Get text reply or XML
Parse it (if need)
Use DHTML principles to change existing content
• document.getElementById(ID).innerText || .innerHTML
XML – WHAT IS THIS?
eXtensible Markup Language
– tag based;
– has DOM structure;
languages written in XML specify:
− names of tags in XHTML: h1, div, img, etc.
− names of attributes in XHTML: id/class, src, href, etc.
− rules about how they go together in XHTML: inline vs.
block-level elements
XML – RESTRICTIONS
Should have header and root element;
Tags are case sensitive;
< and & should be encoded
• >, single and double quotes should be encoded too
Tags should be nested properly
The best practice is to use schemata or DTD
XML – RESTRICTIONS
Should have header and root element;
Tags are case sensitive;
< and & should be encoded
• >, single and double quotes should be encoded too
Tags should be nested properly
The best practice is to use schemata or DTD
ANATOMY OF AN XML FILE
<?xml version="1.0" encoding="UTF-8"?> <!-- XML prolog -->
<messages> <!-- root element -->
<id>1</id> <!-- element (“tag") -->
<login>
Tom <!-- content of element -->
</login>
<message lang="engl"> <!-- attribute and its value -->
Hi Nick!
</message>
</messages>
JSON
JavaScript Object Notation (JSON):
− Data format that represents data as a set of
JavaScript objects
− invented by JS guru Douglas Crockford of Yahoo!
− natively supported by all modern browsers (and
libraries to support it in old ones)
− not yet as popular as XML, but steadily rising due
to its simplicity and ease of use
JSON SYNTAX
JSON is object
It can contain:
– “name” : “value” pairs;
– objects
• {
• “name1” : “value1”, // comma required;
• “name2” : “value2”
• }
– arrays: “arr” : [“val1”, “val2”, “val3”]
– // Java-style comments allowed
Any value could be:
• integer • “string”
• true/false/null • object or array
JSON HANDLE
var s =
‘{“name”: “value”,
“arr”: [1,2,33,40,],
“obj”: {“n1”: “v1”, “n2”: “v2”}
}’;
var jsonObj = JSON.parse(s);
// jsonObj.name = “value”;
// jsonObj.arr[2] = 33;
// jsonObj.obj.n2 = “v2”;
REFERENCES
http://google.com
http://www.w3.org/Protocols/rfc2616/rfc2616.html
http://www.w3.org/TR/XMLHttpRequest/
https://github.com/oyvindkinsey/easyXDM#readme
http://msdn.microsoft.com/en-us/library/cc288060(v=vs.85).aspx (XDR)
http://json.org
Thank you!
Andrii Siusko
skype: asyusko
mail: asyusko@gmail.com

More Related Content

What's hot (20)

PPTX
MongoDB basics & Introduction
Jerwin Roy
 
PDF
Node Js, AngularJs and Express Js Tutorial
PHP Support
 
KEY
Benefits of using MongoDB: Reduce Complexity & Adapt to Changes
Alex Nguyen
 
PPTX
Using Webservice in iOS
Mahboob Nur
 
PPTX
Node js crash course session 2
Abdul Rahman Masri Attal
 
PPT
Java XML Parsing
srinivasanjayakumar
 
PDF
Xml parsing
Malintha Adikari
 
PPTX
Node js crash course session 5
Abdul Rahman Masri Attal
 
PPTX
Introduction to JSON & AJAX
Collaboration Technologies
 
PPTX
Comparison with storing data using NoSQL(CouchDB) and a relational database.
eross77
 
PPTX
Internet and Web Technology (CLASS-7) [XML and AJAX] | NIC/NIELIT Web Technology
Ayes Chinmay
 
PDF
Mongo db basics
Harischandra M K
 
PPTX
Introduction to mongo db
NexThoughts Technologies
 
PPTX
[Mas 500] Data Basics
rahulbot
 
PPT
Connecting to a REST API in iOS
gillygize
 
PDF
Scala with mongodb
Knoldus Inc.
 
PPT
Json
Manav Prasad
 
PPTX
Sql Server 2016 and JSON
Greg McMurray
 
PDF
Difference between xml and json
Umar Ali
 
MongoDB basics & Introduction
Jerwin Roy
 
Node Js, AngularJs and Express Js Tutorial
PHP Support
 
Benefits of using MongoDB: Reduce Complexity & Adapt to Changes
Alex Nguyen
 
Using Webservice in iOS
Mahboob Nur
 
Node js crash course session 2
Abdul Rahman Masri Attal
 
Java XML Parsing
srinivasanjayakumar
 
Xml parsing
Malintha Adikari
 
Node js crash course session 5
Abdul Rahman Masri Attal
 
Introduction to JSON & AJAX
Collaboration Technologies
 
Comparison with storing data using NoSQL(CouchDB) and a relational database.
eross77
 
Internet and Web Technology (CLASS-7) [XML and AJAX] | NIC/NIELIT Web Technology
Ayes Chinmay
 
Mongo db basics
Harischandra M K
 
Introduction to mongo db
NexThoughts Technologies
 
[Mas 500] Data Basics
rahulbot
 
Connecting to a REST API in iOS
gillygize
 
Scala with mongodb
Knoldus Inc.
 
Sql Server 2016 and JSON
Greg McMurray
 
Difference between xml and json
Umar Ali
 

Similar to Ajax xml json (20)

DOCX
Copy of ajax tutorial
Abhishek Kesharwani
 
PPT
AJAX.ppt
karan419841
 
PPT
AJAX
ankurgupta
 
PDF
How to make Ajax work for you
Simon Willison
 
PPTX
Data exchange over internet (XML vs JSON)
Wajahat Shahid
 
PPTX
HSHDGDGDHDYDUDUDUDHDHDHSHAHAHSHSBDHDHDHDHDHD
srlegaspi2101
 
PPT
Ajax
TSUBHASHRI
 
PPTX
Web Development Course - AJAX & JSON by RSOLUTIONS
RSolutions
 
PPTX
Web-Engineering-Lec-14 (1) .pptx
iamayesha2526
 
PPTX
Web-Engineering-Lec-14 (1 ).pptx
iamayesha2526
 
PDF
Building Applications Using Ajax
s_pradeep
 
PPT
Ajax
sujaykumar
 
PPTX
ajax - the basics
Arnelle Balane
 
PDF
AJAX - An introduction
Eleonora Ciceri
 
PPTX
AJAX and JSON
Julie Iskander
 
PDF
Ajaxtechnicalworkshopshortversion 1224845432835700-8
anuradha raheja
 
PPT
Ajax Introduction
Oliver Cai
 
Copy of ajax tutorial
Abhishek Kesharwani
 
AJAX.ppt
karan419841
 
How to make Ajax work for you
Simon Willison
 
Data exchange over internet (XML vs JSON)
Wajahat Shahid
 
HSHDGDGDHDYDUDUDUDHDHDHSHAHAHSHSBDHDHDHDHDHD
srlegaspi2101
 
Web Development Course - AJAX & JSON by RSOLUTIONS
RSolutions
 
Web-Engineering-Lec-14 (1) .pptx
iamayesha2526
 
Web-Engineering-Lec-14 (1 ).pptx
iamayesha2526
 
Building Applications Using Ajax
s_pradeep
 
ajax - the basics
Arnelle Balane
 
AJAX - An introduction
Eleonora Ciceri
 
AJAX and JSON
Julie Iskander
 
Ajaxtechnicalworkshopshortversion 1224845432835700-8
anuradha raheja
 
Ajax Introduction
Oliver Cai
 
Ad

Recently uploaded (20)

PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
Ad

Ajax xml json