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
+5.3k Javascript : Change page title to get viewer attention
+9.6k Golang : Convert(cast) string to int64
+62.8k Golang : Convert HTTP Response body to string
+5.1k Golang : micron to centimeter example
+24.6k Golang : Change file read or write permission example
+9.6k Golang : Extract or copy items from map based on value
+10.4k Golang : Detect number of faces or vehicles in a photo
+15.9k Golang : Intercept Ctrl-C interrupt or kill signal and determine the signal type
+6.3k Golang : Extract sub-strings
+7.6k Golang : Handling Yes No Quit query input
+41.4k Golang : How to count duplicate items in slice/array?
+11.6k Swift : Convert (cast) Float to String