Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
JavaScript and JSON Essentials

You're reading from   JavaScript and JSON Essentials If you fancy a less verbose data format than CSV or XML, then JSON could be for you. This tutorial will teach you about using JSON with JavaScript for effective local storage or Internet transfers.

Arrow left icon
Product type Paperback
Published in Oct 2013
Publisher Packt
ISBN-13 9781783286034
Length 120 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Sai S Sriparasa Sai S Sriparasa
Author Profile Icon Sai S Sriparasa
Sai S Sriparasa
Arrow right icon
View More author details
Toc

Making your first AJAX call


Now that we have an active JSON data feed, it is about time to make our first AJAX call. We will look at two approaches of making an AJAX call; these approaches come from different periods in time. The first approach will use basic JavaScript so that we understand what happens behind the scenes when an AJAX call is made. Once we understand the concept of AJAX, we will use a popular JavaScript library to make the same AJAX call but with simpler code. Let's take a look at our first approach using basic JavaScript:

We will begin with our basic index.html file that loads an external JavaScript file. This JavaScript file performs the AJAX call to fetch the students JSON feed.

Let us take a look at index.js:

This is the original way in which an AJAX call is made to a live web server; let's break this script into pieces and investigate it piece by piece:

In the preceding snippet we are creating an instance of the XMLHttpRequest object. The XMLHttpRequest object lets us make...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image