SlideShare a Scribd company logo
AJAX and JSON
Lecture Outline

 JSON

 AJAX
AJAX and JSON
JSON

 http://www.json.org/

 A lightweight data-interchange format.

 Humans readable.

 Easy for machines to parse and generate.

 A text format that is completely language independent.

 An ideal data-interchange language.
JSON (Cont’d)

 Built on two structures:
    A collection of name/value pairs (object)
        An object begins with { and ends with }. Each name is
         followed by : and the name/value pairs are separated by
         ‘,’ .
        An ordered list of values (array)
              An array begins with [ and ends with ]. Values are
               separated by ‘,’ .

 A value can be a string in double quotes, or a number, or
  true or false or null, or an object or an array.
JSON (Cont’d)

 There are libraries in nearly all languages to parse
  JSON files.

 In JavaScript, these libraries contain function to
  convert from objects to json text and vice versa.
Try JSON Library
AJAX and JSON
AJAX

 Allows client-side JavaScript to request and receive
  data from a server without refreshing the web page.

 Only partial reload occurs

 Jesse James Garrett originally coined the term Ajax in
  2005.
  (www.adaptivepath.com/publications/essays/archives
  /000385.php ).

 Let web applications look and behave more like
  desktop applications than web sites,
AJAX and JSON
Steps to send a simple ajax
           request
1. Create XMLHttpRequest Object

2. Open the request, set the HTTP method and URL

3. Set callback for onreadychange

4. Send asynchronous request

5. Create an event to call the previous steps
AJAX and JSON
Sending Request

 var xhr = new XMLHttpRequest();

 xhr.onreadystatechange = myCallback;

 xhr.open('GET', 'somefile.txt', true);

 xhr.send('');
For Cross-browser
  compatibility
readyState values

Value       Description
0           Uninitialized
1           Loading
2           Loaded
3           Interactive
4           Complete
Some status values

Value        Description
200          Ok
204          No content
401          UnAuthorized
404          Not Found
411          Request Timeout
Processing Request

function myCallback() {
   if (xhr.readyState < 4) {
        return;
   }
   if (xhr.status !== 200) {
        alert('Error!'); // the HTTP status code is not OK
        return;
   }
        alert(xhr.responseText);
   }
Try Ajax
Use Developer tools
References
 Object-Oriented JavaScript Create Scalable, reusable, high
  quality JavaScript applications and libraries, Stoyan Stefanov,
  2008.

 ECMAScript Language Specification, 5.1 edition, July 2011,
  http://www.ecma-international.org/

 Beginning JavaScript, 4th Edition, Paul Wilton, Jeremy
  McPeak, 2010

More Related Content

What's hot (20)

PPSX
Functional patterns and techniques in C#
Péter Takács
 
PPT
6 xml parsing
gauravashq
 
PPTX
32sql server
Sireesh K
 
PDF
Lambdas HOL
Oleg Tsal-Tsalko
 
PPTX
Sax parser
Mahara Jothi
 
PPTX
30csharp
Sireesh K
 
PDF
Xml parsing
Malintha Adikari
 
ODP
jTransfo lightning talk
Joachim Van der Auwera
 
PDF
Parsing XML Data
Mu Chun Wang
 
PDF
3. Java Script
Jalpesh Vasa
 
PPTX
06 xml processing-in-.net
glubox
 
PPTX
Javascript
Prashant Kumar
 
PDF
ClevelandDayofDotNet_JoshClark
Joshua S. Clark, CISSP
 
PDF
Odoo Technical Concepts Summary
Mohamed Magdy
 
ODP
Functional programming with Scala
Neelkanth Sachdeva
 
PPT
XML SAX PARSING
Eviatar Levy
 
PDF
Angular - Chapter 2 - TypeScript Programming
WebStackAcademy
 
ODP
Functions & closures
Knoldus Inc.
 
PPTX
Introduction to RxJS
Abul Hasan
 
ODP
Modern Java Features
Florian Hopf
 
Functional patterns and techniques in C#
Péter Takács
 
6 xml parsing
gauravashq
 
32sql server
Sireesh K
 
Lambdas HOL
Oleg Tsal-Tsalko
 
Sax parser
Mahara Jothi
 
30csharp
Sireesh K
 
Xml parsing
Malintha Adikari
 
jTransfo lightning talk
Joachim Van der Auwera
 
Parsing XML Data
Mu Chun Wang
 
3. Java Script
Jalpesh Vasa
 
06 xml processing-in-.net
glubox
 
Javascript
Prashant Kumar
 
ClevelandDayofDotNet_JoshClark
Joshua S. Clark, CISSP
 
Odoo Technical Concepts Summary
Mohamed Magdy
 
Functional programming with Scala
Neelkanth Sachdeva
 
XML SAX PARSING
Eviatar Levy
 
Angular - Chapter 2 - TypeScript Programming
WebStackAcademy
 
Functions & closures
Knoldus Inc.
 
Introduction to RxJS
Abul Hasan
 
Modern Java Features
Florian Hopf
 

Viewers also liked (12)

PDF
How to make Ajax work for you
Simon Willison
 
PDF
JSON and AJAX JumpStart
dominion
 
PPSX
Dynamic webpages using AJAX & JSON
Christiaan Rakowski
 
PPT
Ajax by Examples 2
Yenwen Feng
 
PDF
08 ajax
Ynon Perek
 
PDF
When Ajax Attacks! Web application security fundamentals
Simon Willison
 
PPTX
Introduction to JSON & AJAX
Collaboration Technologies
 
PPTX
HTTP, JSON, REST e AJAX com AngularJS
Rodrigo Branas
 
PDF
Introduction to JSON
Kanda Runapongsa Saikaew
 
PDF
Refreshing Your UI with HTML5, Bootstrap and CSS3
Matt Raible
 
PPT
External Data Access with jQuery
Doncho Minkov
 
PPTX
Ajax ppt - 32 slides
Smithss25
 
How to make Ajax work for you
Simon Willison
 
JSON and AJAX JumpStart
dominion
 
Dynamic webpages using AJAX & JSON
Christiaan Rakowski
 
Ajax by Examples 2
Yenwen Feng
 
08 ajax
Ynon Perek
 
When Ajax Attacks! Web application security fundamentals
Simon Willison
 
Introduction to JSON & AJAX
Collaboration Technologies
 
HTTP, JSON, REST e AJAX com AngularJS
Rodrigo Branas
 
Introduction to JSON
Kanda Runapongsa Saikaew
 
Refreshing Your UI with HTML5, Bootstrap and CSS3
Matt Raible
 
External Data Access with jQuery
Doncho Minkov
 
Ajax ppt - 32 slides
Smithss25
 
Ad

Similar to AJAX and JSON (20)

PPTX
Web technologies-course 10.pptx
Stefan Oprea
 
PPTX
JSON
Yoga Raja
 
PPTX
JSON & AJAX.pptx
dyumna2
 
PDF
Lec 7
maamir farooq
 
PPTX
Web Development Course - AJAX & JSON by RSOLUTIONS
RSolutions
 
PPT
Web Programming using Asynchronous JavaX
SivanN6
 
PPT
AJAX
ankurgupta
 
PDF
Introduction to JSON & Ajax
Seble Nigussie
 
PPTX
Introduction to JSON & AJAX
Raveendra R
 
PPT
Ajax
Manav Prasad
 
PPTX
Web-Engineering-Lec-14 (1) .pptx
iamayesha2526
 
PPTX
Web-Engineering-Lec-14 (1 ).pptx
iamayesha2526
 
PPT
Ajax
ch samaram
 
PPTX
AJAX.pptx
Ganesh Chavan
 
PPT
Ajax
sujaykumar
 
PPT
PHP - Introduction to PHP AJAX
Vibrant Technologies & Computers
 
PDF
Web 11 | AJAX + JSON + PHP
Mohammad Imam Hossain
 
PDF
Introduction to AJAX
Abzetdin Adamov
 
Web technologies-course 10.pptx
Stefan Oprea
 
JSON
Yoga Raja
 
JSON & AJAX.pptx
dyumna2
 
Web Development Course - AJAX & JSON by RSOLUTIONS
RSolutions
 
Web Programming using Asynchronous JavaX
SivanN6
 
Introduction to JSON & Ajax
Seble Nigussie
 
Introduction to JSON & AJAX
Raveendra R
 
Web-Engineering-Lec-14 (1) .pptx
iamayesha2526
 
Web-Engineering-Lec-14 (1 ).pptx
iamayesha2526
 
AJAX.pptx
Ganesh Chavan
 
PHP - Introduction to PHP AJAX
Vibrant Technologies & Computers
 
Web 11 | AJAX + JSON + PHP
Mohammad Imam Hossain
 
Introduction to AJAX
Abzetdin Adamov
 
Ad

More from Julie Iskander (20)

PPTX
HTML 5
Julie Iskander
 
PPTX
Data structures and algorithms
Julie Iskander
 
PPTX
C for Engineers
Julie Iskander
 
PPTX
Design Pattern lecture 3
Julie Iskander
 
PPTX
Scriptaculous
Julie Iskander
 
PPTX
Prototype Framework
Julie Iskander
 
PPTX
Design Pattern lecture 4
Julie Iskander
 
PPTX
Design Pattern lecture 2
Julie Iskander
 
PPTX
Design Pattern lecture 1
Julie Iskander
 
PPTX
Ajax and ASP.NET AJAX
Julie Iskander
 
PPTX
jQuery
Julie Iskander
 
PPTX
ASP.NET Lecture 5
Julie Iskander
 
PPTX
ASP.NET lecture 8
Julie Iskander
 
PPTX
ASP.NET Lecture 7
Julie Iskander
 
PPTX
ASP.NET Lecture 6
Julie Iskander
 
PPTX
ASP.NET Lecture 4
Julie Iskander
 
PPTX
ASP.NET Lecture 3
Julie Iskander
 
PPTX
ASP.NET Lecture 2
Julie Iskander
 
PPTX
ASP.NET Lecture 1
Julie Iskander
 
PPTX
Object Oriented JavaScript
Julie Iskander
 
Data structures and algorithms
Julie Iskander
 
C for Engineers
Julie Iskander
 
Design Pattern lecture 3
Julie Iskander
 
Scriptaculous
Julie Iskander
 
Prototype Framework
Julie Iskander
 
Design Pattern lecture 4
Julie Iskander
 
Design Pattern lecture 2
Julie Iskander
 
Design Pattern lecture 1
Julie Iskander
 
Ajax and ASP.NET AJAX
Julie Iskander
 
ASP.NET Lecture 5
Julie Iskander
 
ASP.NET lecture 8
Julie Iskander
 
ASP.NET Lecture 7
Julie Iskander
 
ASP.NET Lecture 6
Julie Iskander
 
ASP.NET Lecture 4
Julie Iskander
 
ASP.NET Lecture 3
Julie Iskander
 
ASP.NET Lecture 2
Julie Iskander
 
ASP.NET Lecture 1
Julie Iskander
 
Object Oriented JavaScript
Julie Iskander
 

Recently uploaded (20)

PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
PDF
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
PDF
Human-centred design in online workplace learning and relationship to engagem...
Tracy Tang
 
PPTX
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
July Patch Tuesday
Ivanti
 
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
Human-centred design in online workplace learning and relationship to engagem...
Tracy Tang
 
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 

AJAX and JSON

  • 4. JSON  http://www.json.org/  A lightweight data-interchange format.  Humans readable.  Easy for machines to parse and generate.  A text format that is completely language independent.  An ideal data-interchange language.
  • 5. JSON (Cont’d)  Built on two structures:  A collection of name/value pairs (object)  An object begins with { and ends with }. Each name is followed by : and the name/value pairs are separated by ‘,’ .  An ordered list of values (array)  An array begins with [ and ends with ]. Values are separated by ‘,’ .  A value can be a string in double quotes, or a number, or true or false or null, or an object or an array.
  • 6. JSON (Cont’d)  There are libraries in nearly all languages to parse JSON files.  In JavaScript, these libraries contain function to convert from objects to json text and vice versa.
  • 9. AJAX  Allows client-side JavaScript to request and receive data from a server without refreshing the web page.  Only partial reload occurs  Jesse James Garrett originally coined the term Ajax in 2005. (www.adaptivepath.com/publications/essays/archives /000385.php ).  Let web applications look and behave more like desktop applications than web sites,
  • 11. Steps to send a simple ajax request 1. Create XMLHttpRequest Object 2. Open the request, set the HTTP method and URL 3. Set callback for onreadychange 4. Send asynchronous request 5. Create an event to call the previous steps
  • 13. Sending Request  var xhr = new XMLHttpRequest();  xhr.onreadystatechange = myCallback;  xhr.open('GET', 'somefile.txt', true);  xhr.send('');
  • 14. For Cross-browser compatibility
  • 15. readyState values Value Description 0 Uninitialized 1 Loading 2 Loaded 3 Interactive 4 Complete
  • 16. Some status values Value Description 200 Ok 204 No content 401 UnAuthorized 404 Not Found 411 Request Timeout
  • 17. Processing Request function myCallback() { if (xhr.readyState < 4) { return; } if (xhr.status !== 200) { alert('Error!'); // the HTTP status code is not OK return; } alert(xhr.responseText); }
  • 19. References  Object-Oriented JavaScript Create Scalable, reusable, high quality JavaScript applications and libraries, Stoyan Stefanov, 2008.  ECMAScript Language Specification, 5.1 edition, July 2011, http://www.ecma-international.org/  Beginning JavaScript, 4th Edition, Paul Wilton, Jeremy McPeak, 2010