I'm trying to get a JSON response from Kraken api to convert currences, but all the methods that I found (also here in stackoverflow), though they work for other sites (like "https://api.cryptonator.com/api/currencies" or the one discussed in the stackoverflow thread "/questions/12460378/how-to-get-json-from-url-in-javascript"), they don't work at all with kraken (example "https://api.kraken.com/0/public/Assets"), I don't get any response, as the URL is broken, but by accessing it with the browser I can clearly see the JSON object.
I'm using pure javascript because I'm working in wordpress, but if necessary I can add jquery (thought I would continue with js in order to not waste other time).
Untill now, I tried:
function httpGet(theUrl)
{
var xmlHttp = null;
xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", theUrl, false );
xmlHttp.send( null );
return xmlHttp.responseText;
}
prove = eval('(' + httpGet("https://api.kraken.com/0/public/Assets") + ')');
Working with both cryptonator and yahoo (the 2nd example), but not with kraken.
var getJSON = function(url, callback) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'json';
xhr.onload = function() {
var status = xhr.status;
if (status == 200) {
callback(null, xhr.response);
} else {
callback(status);
}
};
xhr.send();
};
getJSON('https://api.kraken.com/0/public/Assets',
function(err, data) {
if (err != null) {
alert('Something went wrong: ' + err);
} else {
alert('Your query count: ' + data);
}
});
Same as before. I also tried with jquery but the result is the same, the kraken url is the only not working
$.getJSON("https://api.kraken.com/0/public/Assets", function(data) {
// Get the element with id summary and set the inner text to the result.
$('#summary').text(data.result);
});
I really can't understand why I can't manage to get and parse this damn JSON object from that site while the others are working well, considering also the fact that it gives me a response if I enter the link via browser.
Thanks in advance for the help