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
+9.6k Golang : Edge detection with Sobel method
+10.6k Google Maps URL parameters configuration
+10.4k Golang : Create Temporary File
+34.3k Golang : Upload and download file to/from AWS S3
+21.2k Golang : Use TLS version 1.2 and enforce server security configuration over client
+11.5k Golang : Split strings into command line arguments
+8.2k Golang : Convert(cast) []byte to io.Reader type
+5.1k Golang : Shortening import identifier
+15.3k Golang : Read large file with bufio.Scanner cause token too long error
+4.6k Unix/Linux : secure copying between servers with SCP command examples
+12.4k Golang : Convert IPv4 address to packed 32-bit binary format
+7.9k Golang : Implementing class(object-oriented programming style)