Warning: Trying to access array offset on value of type null in /home/l7yod4xq2ufo/public_html/wp-content/plugins/codepen-embedded-pen-shortcode/codepen.php on line 16
Warning: Trying to access array offset on value of type null in /home/l7yod4xq2ufo/public_html/wp-content/plugins/codepen-embedded-pen-shortcode/codepen.php on line 17
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.
See the Pen Load JsonP File From Cross Domain Server And Store In localStorage() by Peter (@peterdillon) on CodePen.0
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