I'm writing my first jQuery plugin and looking for some help making a JSONP request inside it.
Normally I setup my JSON data inside of a callback function like so
saveDataCommunityPartners({
"newsBlockItems": [
{
"title": "title title title",
"img": "item-img.jpg"
},
{
"title": "title title title",
"img": "item-img.jpg"
}
... and so on and so forth
]
})
Then on a page I call .getJSON()
like so:
$.getJSON("http://i.cdn.turner.com/nba/nba/.element/media/2.0/teamsites/warriors/json/json-redesign-communitypartners.js?callback=?");
And set up the callback function
function saveDataCommunityPartners(data) {
alert("got data");
}
And everything works fine. How would I get this to work inside my plugin? If I do it like it is below, I'm getting a "Uncaught ReferenceError: saveDataCommunityPartners is not defined" error.
(function($) {
$.fn.createNewsBlock = function( options ) {
// Establish defaults
var settings = $.extend({
thisData : {},
pageFilter : "community"
}, options);
$.getJSON("http://i.cdn.turner.com/nba/nba/.element/media/2.0/teamsites/warriors/json/json-redesign-communitypartners.js?callback=?");
function saveDataCommunityPartners(data) {
alert("got data");
}
}(jQuery));
I can either change the plugin, or how I set up the JSON file itself, whatever is recommended. Thanks!