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
+7.5k Golang : Generate human readable password
+6.4k Golang : Skip or discard items of non-interest when iterating example
+26.5k Golang : Convert file content into array of bytes
+5.7k Golang : Extract unicode string from another unicode string example
+11.6k Golang : Convert(cast) bigint to string
+13.7k Golang : Get current time
+6k Golang : How to get capacity of a slice or array?
+30.9k Golang : bufio.NewReader.ReadLine to read file line by line
+6.2k Grep : How to grep for strings inside binary data
+12.4k Swift : Convert (cast) Int or int32 value to CGFloat
+7.2k Golang : Gorrila set route name and get the current route name
+9.5k Golang : interface - when and where to use examples