Bitcoin Forum
May 30, 2024, 04:14:06 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Trying to call Bitcoin price with CoinDesk API using javaScrip(can anyone help?)  (Read 317 times)
Imaginary Entity (OP)
Newbie
*
Offline Offline

Activity: 33
Merit: 0


View Profile
February 18, 2017, 06:05:27 PM
 #1

Hi Guys, I'm trying to call CoinBase's API for up-to-date Bitcoin price for a website I'm trying to create. I'm trying to make it using javaScript. Below is the code I have come up with but I am a bit stuck with it.....  I was hoping someone here might point me in the right direction?


<!DOCTYPE html>
<html>
<head>
   <title> Call coindesk API</title>
</head>
<body>

<script>
   
   function httpGetAsync( "https://api.coindesk.com/v1/bpi/currentprice.json", callback)
{
    var xmlHttp = new XMLHttpRequest();
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
            callback(xmlHttp.responseText);
    }
    xmlHttp.open("GET", "https://api.coindesk.com/v1/bpi/currentprice.json, true)"; // true for asynchronous
    xmlHttp.send(null);
}
</script>

</body>
</html>
nemgun
Hero Member
*****
Offline Offline

Activity: 882
Merit: 533



View Profile WWW
February 18, 2017, 09:33:13 PM
 #2

I advise you to find annother way to request the API, the problem with most APIs is that Access control allow origin header is not set or restricted server-side, it means that you can't use common XHR requests, maybe using jquery, with somme tricks you can manage to get a responce, but the best you could do is to use the NodeJS integration, or to call it using PHP, Perl, or any other languague you know, or, you are able to use.
Imaginary Entity (OP)
Newbie
*
Offline Offline

Activity: 33
Merit: 0


View Profile
February 18, 2017, 09:52:48 PM
 #3

Okay thanks nemgum, at least I know I'm barking up the wrong tree!

I think I will put the task out to freelancers
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!