Hi, I am trying to extract something from an API, which should return me a string with the recent prices for Ethereum.
After that I would like to parse the string and drop all data, so that only the latest price is returned.
This is the code I have so far, however it does not return anything and I am stuck on this and how to parse the code.
Any help is greatly appreciated! Thanks.
{
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://api.kraken.com/0/public/Ticker?pair=ETHEUR', true);
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
console.log(xhr.responseText);
}
}
};
xhr.send()to send the requestecho json_encode($assoc_array_here);on your PHP page. Of course, using the raw XMLHttpRequest withXMLHttpRequestInstance.responseTextwill give you that associative Array as a String. UseJSON.parse(XMLHttpRequestInstance.responseText)oreval('('+XMLHttpRequestInstance.responseText+')'). The later is more backward compatible.JSON.parse()is what most will recommend.