May 2017
Intermediate to advanced
448 pages
10h 10m
English
In Chapter 6, Sending Data with Ajax, we saw that JSONP is simply JSON with an added layer of server behavior allowing requests to be made from a different site. When a request is made for JSONP data, a special query string parameter is provided that allows the requesting script to process the data. This parameter can be called anything the JSONP server wishes; in the case of the GitHub API, the parameter uses the default name, callback.
Because the default callback name is used, the only setup required to make a JSONP request is to declare to jQuery that jsonp is the data type we are expecting:
$(() => { $('#ajax-form') .on('submit', (e) => { e.preventDefault(); $.ajax({ url: 'https://api.github.com/search/repositories', ...Read now
Unlock full access