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
+19.6k Golang : How to Set or Add Header http.ResponseWriter?
+4.8k Linux/MacOSX : How to symlink a file?
+19.3k Golang : Execute shell command
+11.5k Golang : How to flush a channel before the end of program?
+10k Random number generation with crypto/rand in Go
+30.8k Golang : Remove characters from string example
+5.8k Golang : Frobnicate or tweaking a string example
+5.9k Linux/Unix/PHP : Restart PHP-FPM
+17.4k Google Chrome : Your connection to website is encrypted with obsolete cryptography
+9.5k Golang : How to protect your source code from client, hosting company or hacker?
+7.8k Golang : Convert(cast) io.Reader type to string
+19.7k Golang : Example for DSA(Digital Signature Algorithm) package functions