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
+9.6k Javascript : Read/parse JSON data from HTTP response
+34.1k Golang : Create x509 certificate, private and public keys
+6.9k Get Facebook friends working in same company
+14k Golang : How to check if a file is hidden?
+8.1k Golang : Handle Palindrome string with case sensitivity and unicode
+16.3k Golang : How to extract links from web page ?
+6.4k Golang : Detect face in uploaded photo like GPlus
+11.4k Golang : How to flush a channel before the end of program?
+9.6k Golang : Read file with ioutil
+22.8k Golang : Round float to precision example
+6.6k Golang : Spell checking with ispell example