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
+19.1k Golang : Populate dropdown with html/template example
+6.6k Golang : Humanize and Titleize functions
+18.4k Golang : Write file with io.WriteString
+5.3k Golang : What is StructTag and how to get StructTag's value?
+7.5k Android Studio : AlertDialog to get user attention example
+28.7k Golang : Detect (OS) Operating System
+16.9k Golang : How to save log messages to file?
+9k Golang : Gonum standard normal random numbers example
+8.8k Golang : GMail API create and send draft with simple upload attachment example
+8.2k Golang : Check if integer is power of four example
+5.4k Golang : Display advertisement images or strings on random order
+14.4k Golang : How to determine if user agent is a mobile device example