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
+10.4k Golang : Byte format example
+12.1k Golang : Image to ASCII art example
+5.6k Golang : Derive cryptographic key from passwords with Argon2
+12k CodeIgniter : "Fatal error: Cannot use object of type stdClass as array" message
+8.6k Golang : How to check if a website is served via HTTPS
+19.2k Golang : Underscore or snake_case to camel case example
+12.9k Elastic Search : Mapping date format and sort by date
+5.6k Golang : Totalize or add-up an array or slice example
+8.2k Golang : Read file with ioutil
+18.7k Golang : Accept input from user with fmt.Scanf skipped white spaces and how to fix it
+6.8k Golang : Scan files for certain pattern and rename part of the files