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.6k Golang : Find age or leap age from date of birth example
+43.1k Golang : Convert []byte to image
+7.8k Golang : Regular Expression find string example
+8.3k Golang : Implementing class(object-oriented programming style)
+11.7k Golang : Verify Linux user password again before executing a program example
+10.2k Golang : Embed secret text string into binary(executable) file
+11.4k Golang : Format numbers to nearest thousands such as kilos millions billions and trillions
+15.9k Golang : Read large file with bufio.Scanner cause token too long error
+7.9k Golang : Grayscale Image
+18.5k Golang : Set, Get and List environment variables
+9.5k Golang : Validate IPv6 example
+8.4k Golang : Generate Datamatrix barcode