Created
June 3, 2013 06:43
-
-
Save tcdevs/5696461 to your computer and use it in GitHub Desktop.
Load a JSON data Object from another domain (with callback function)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jsonCallback( | |
{ | |
"sites": | |
[ | |
{ | |
"siteName": "JQUERY4U", | |
"domainName": "http://www.jquery4u.com", | |
"description": "#1 jQuery Blog for your Daily News, Plugins, Tuts/Tips & Code Snippets." | |
}, | |
{ | |
"siteName": "BLOGOOLA", | |
"domainName": "http://www.blogoola.com", | |
"description": "Expose your blog to millions and increase your audience." | |
}, | |
{ | |
"siteName": "PHPSCRIPTS4U", | |
"domainName": "http://www.phpscripts4u.com", | |
"description": "The Blog of Enthusiastic PHP Scripters" | |
} | |
] | |
} | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Reference: http://www.jquery4u.com/json/jsonp-examples/ | |
(function($) { | |
var url = 'http://www.jquery4u.com/scripts/jquery4u-sites.json?callback=?'; | |
$.ajax({ | |
type: 'GET', | |
url: url, | |
async: false, | |
jsonpCallback: 'jsonCallback', | |
contentType: "application/json", | |
dataType: 'jsonp', | |
success: function(json) { | |
console.dir(json.sites); | |
}, | |
error: function(e) { | |
console.log(e.message); | |
} | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment