Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
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

Implementing JSONP


We are using the same URL as before to fetch the data, but we have added the jsonp parameter and are setting it to getRedditData; it is important to note that the feed is now padded into our callback getRedditData. Now let's replace the URL property in our earlier script to create a new script that will fetch us the JSON feed.

A few properties such as url and dataType have been modified and a few new properties such as contentType and jsonpCallback have been added. We have already discussed the change in the url property, so let us look at the other properties.

Earlier, the dataType property was set to json as the incoming feed was of type json, but now the JSON feed is being padded into a callback, and it has to be switched so that the browser expects a callback rather than JSON itself. The new properties that have been added are contentType and jsonpCallback; the property contentType specifies the type of content being sent to the web server. jsonpCallback takes the name...

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 €18.99/month. Cancel anytime