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
+4.8k Golang : Calculate a pip value and distance to target profit example
+7.4k Javascript : Push notifications to browser with Push.js
+7.7k Golang : Get today's weekday name and calculate target day distance example
+5.9k Fix ERROR 2003 (HY000): Can't connect to MySQL server on 'IP address' (111)
+15.9k Golang : Get sub string example
+6.8k Golang : Calculate BMI and risk category
+17.4k Golang : Find smallest number in array
+5.9k PHP : Get client IP address
+9.8k Golang : Function wrapper that takes arguments and return result example
+5.2k Golang : Pad file extension automagically
+13.4k Golang : Qt progress dialog example