JasonP and Cross Domain Access

Last Updated on April 16, 2016

In the jQuery ajax request, the use of a callback function wraps our data to allow the cross domain access to happen.

$.ajax({
 dataType: 'jsonp',
 jsonpCallback: 'jsonCallback',
 // ...

This allows us to request the JSON via AJAX using JSONP (json + padding) and the callback function we created around the JSON content as seen here on this file that sits on my personal server (not codepen)

jsonCallback({
  "name": "local storage app",
  "version": "1.1.1",
  "description": "Storing a json object"
});

Here is a pen of the final result.
[codepen_embed height=”268″ theme_id=”0″ slug_hash=”XXRJPZ” default_tab=”result” user=”peterdillon”]See the Pen Load JsonP File From Cross Domain Server And Store In localStorage() by Peter (@peterdillon) on CodePen.[/codepen_embed]

I found some pretty useful documentation here:
Sitepoint article. I could not get the second non-callback method to work. Any help there would be appreciated.
Sam Croft article.
Oscar Godson article.
Stack Overflow