Skip to Main Content
JavaScript and Open Data
book

JavaScript and Open Data

by Robert Jeansoulin
August 2018
Intermediate to advanced content levelIntermediate to advanced
272 pages
5h 3m
English
Wiley-ISTE
Content preview from JavaScript and Open Data

14Data Served by JSONP

We know that the “padding” of JSON to JSONP is a workaround to avoid the rule of the same origin policy. JSONP was experimented on at the end of 2005 (Bob Ippolito), in order to allow an object literal (JSON format), to be readable as a valid JavaScript code when the script engine is triggered by the tag <script>. This technology is used by some major actors, such as Google, Adobe and Yahoo, but raises some concerns about the risk of “script injection”: in other words, the possibility of some malicious code hidden in the data.

Ultimately, the future of JSONP technology seems to be linked to the (commercial) decisions of these giants, but APIs are available today and are of interest wherever a SOP constraint is imposed. Below are three examples of this technology being used.

14.1. Serving RSS feeds through Yahoo Query Language

Yahoo proposes a request service whose syntax mimics an SQL command line: it is named Yahoo Query Language (YQL). For instance, a YQL request is able to query and send back data from an RSS feed.

This example is made up of two scripts. The first defines the function rssReturn which will be used as the callback wrapper in JSONP: it reads a selection of the RSS data, such as title, link and desc, and formats a printable answer. The second script is the HTTP request of the JSONP at the Yahoo server, with the YQL syntax: q=select*.., format=json and callback=rssReturn (the same callback name).

<h1> YQL and RSS: Yahoo serving "ycombinator.com" ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Data Wrangling with JavaScript

Data Wrangling with JavaScript

Ashley Davis
Web Applications with Javascript or Java

Web Applications with Javascript or Java

Gerd Wagner, Mircea Diaconescu

Publisher Resources

ISBN: 9781786302045