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.7k Golang : A program that contain another program and executes it during run-time
+38.9k Golang : How to iterate over a []string(array)
+7k CloudFlare : Another way to get visitor's real IP address
+9.9k Golang : Test a slice of integers for odd and even numbers
+12.5k Golang : Add ASCII art to command line application launching process
+6.1k Golang : How to get capacity of a slice or array?
+16.1k Golang : convert string or integer to big.Int type
+8.1k Golang : Find relative luminance or color brightness
+6.6k Golang : Get expvar(export variables) to work with multiplexer
+8.2k Golang : Count leading or ending zeros(any item of interest) example
+6k Java : Human readable password generator
+7k Golang : Validate credit card example