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
+17.1k Golang : How to get hour, minute, second from time?
+5.9k Golang : How to call function inside template with template.FuncMap
+4.8k Unix/Linux : How to test user agents blocked successfully ?
+6.4k Golang : Get YouTube playlist
+5k Facebook : How to force facebook to scrape latest URL link data?
+9k Golang : Use regular expression to get all upper case or lower case characters example
+44.1k Golang : Read tab delimited file with encoding/csv package
+13.3k Golang : How to shuffle elements in array or slice?
+5.1k Golang : Debug with Godebug
+14k Golang : rune literal not terminated error
+5k Golang : How to verify input is rune?
+9.6k Golang : Get UDP client IP address and differentiate clients by port number