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
+12.9k Swift : Convert (cast) Int or int32 value to CGFloat
+7.3k Golang : Check if one string(rune) is permutation of another string(rune)
+10.7k Golang : Flip coin example
+7.1k Golang : Squaring elements in array
+11.3k Google Maps URL parameters configuration
+5.9k Golang : Detect variable or constant type
+4.4k Javascript : How to show different content with noscript?
+35.2k Golang : Upload and download file to/from AWS S3
+29.6k Golang : Login(Authenticate) with Facebook example
+6.2k Java : Human readable password generator
+9.5k Golang : Create unique title slugs example
+6.6k Golang : Convert an executable file into []byte example