Javascript : How to get JSON data from another website with JQuery or Ajax ?
A very common task for developing front-end. I used to write this a lot but some how forgotten about it today after couple of years. So....
Problem :
How to get JSON data from another website with JQuery or Ajax ?
Solution :
first example:
var json = 'http://anotherwebsite.com/that/returnsjsonresult/';
$.getJSON(json, function(result){
$.ajax({
type:'GET',
url:json,
dataType:'JSONP',
data: result,
success: function(msg){
// do stuff with the msg
console.log('json result returned');
}
});
});
another example :
var json = 'http://anotherwebsite.com/that/returnsjsonresult/';
$.getJSON( json, function( result ) {
console.log( "JSON Data: " + result.person[2].name );
});
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+11k Golang : How to transmit update file to client by HTTP request example
+8k Swift : Convert (cast) String to Float
+16.2k Golang : How to reverse elements order in map ?
+6.9k Golang : Experimental emojis or emoticons icons programming language
+11.7k SSL : The certificate is not trusted because no issuer chain was provided
+7.5k Golang : Individual and total number of words counter example
+10.2k Golang : Identifying Golang HTTP client request
+12.6k Golang : HTTP response JSON encoded data
+7k Golang : Decode XML data from RSS feed
+6k Golang : Detect variable or constant type
+22.3k Golang : Securing password with salt
+12.3k Golang : calculate elapsed run time