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
+17.3k Golang : When to use init() function?
+17.8k Golang : Parse date string and convert to dd-mm-yyyy format
+7.9k Golang : Getting Echo framework StartAutoTLS to work
+19.7k Golang : Close channel after ticker stopped example
+5.7k PHP : Convert CSV to JSON with YQL example
+12.9k Android Studio : Highlight ImageButton when pressed on example
+7.5k Golang : Example of custom handler for Gorilla's Path usage.
+35.5k Golang : Strip slashes from string example
+16.1k Golang : Read large file with bufio.Scanner cause token too long error
+12k Golang : Convert decimal number(integer) to IPv4 address
+23.7k Golang : Read a file into an array or slice example
+13.5k Golang : Generate Code128 barcode