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
+7k Findstr command the Grep equivalent for Windows
+31.2k Golang : Regular Expression for alphanumeric and underscore
+18.3k Golang : Determine if directory is empty with os.File.Readdir() function
+4.9k Get website traffic ranking with Similar Web or Alexa
+12.7k Golang : convert rune to unicode hexadecimal value and back to rune character
+5.4k Grep : How to grep for strings inside binary data
+6.8k Golang : get the current working directory of a running program
+6.2k Golang : Trim everything onward after a word
+7.2k Golang : Metaprogramming example of wrapping a function
+14.8k Golang : Generate universally unique identifier(UUID) example
+4.2k Golang : Constant and variable names in native language
+4.4k Unix/Linux : How to archive and compress entire directory ?