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
+6.1k Golang : A simple forex opportunities scanner
+10.1k Golang : Characters limiter example
+4k Fix Google Analytics Redundant Hostnames problem
+12.2k Golang : Date and Time formatting
+4.6k PHP : Convert string to timestamp or datestamp before storing to database(MariaDB/MySQL)
+5.4k Golang : Break string into a slice of characters example
+8.5k Golang : Accessing content anonymously with Tor
+9k Golang : Use regular expression to get all upper case or lower case characters example
+7.2k Golang : Find relative luminance or color brightness
+5.7k Golang : Skip or discard items of non-interest when iterating example
+10.6k CodeIgniter : Import Linkedin data
+13.3k Golang : GUI with Qt and OpenCV to capture image from camera