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
+11.1k Golang : Change date format to yyyy-mm-dd
+9.8k Golang : Convert file content to Hex
+16.1k Golang : Fix cannot convert buffer (type *bytes.Buffer) to type string error
+7k Golang : Hue, Saturation and Value(HSV) with OpenCV example
+30.9k Golang : Convert an image file to []byte
+20.7k Golang : Convert(cast) string to rune and back to string example
+5.6k Linux/MacOSX : Search for files by filename and extension with find command
+11.2k How to tell if a binary(executable) file or web application is built with Golang?
+6.9k Golang : Process json data with Jason package
+9.8k Golang : Convert file unix timestamp to UTC time example
+9.8k Fix ERROR 1045 (28000): Access denied for user 'root'@'ip-address' (using password: YES)
+7.1k Golang : Set horizontal, vertical scroll bars policies and disable interaction on Qt image