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
+6.6k Golang : Muxing with Martini example
+13.9k Golang : How to pass map to html template and access the map's elements
+9.4k Golang : Load ASN1 encoded DSA public key PEM file example
+6.4k Golang : Find the longest line of text example
+18.4k Golang : convert int to string
+9.2k Golang : Changing a RGBA image number of channels with OpenCV
+9.9k Golang : How to profile or log time spend on execution?
+9.4k Golang : Format strings to SEO friendly URL example
+29.9k Golang : How to verify uploaded file is image or allowed file types
+15.4k Golang : Get current time from the Internet time server(ntp) example
+18.4k Unmarshal/Load CSV record into struct in Go
+22.4k Golang : untar or extract tar ball archive example