Bitcoin Forum
June 17, 2024, 08:41:09 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Embed plaintext price from Bitstamp using API (jsonp?)  (Read 1775 times)
amoai (OP)
Newbie
*
Offline Offline

Activity: 35
Merit: 0


View Profile WWW
May 01, 2014, 02:21:41 PM
 #1

How do I fetch Bitstamp's last price quote from their JSON ticker api and have it on my website as plain text?

Here's what I tried with no luck,

Attempt 1)
 
Code:
<div id="pricebar">
Buy Price: <span id="buyprice"> </span><br>
Sell Price: <span id="bidprice"> </span><br>
</div>

Code:
<script>
  $.ajax(
  type:'GET',
  url: "https://www.bitstamp.net/api/ticker/",
  success:function(feed) {
var priceobj = {
"liveprice":"last",
"bidprice":"bid",
};
document.getElementById("buyprice").innerHTML=priceobj.liveprice;
document.getElementById("bidprice").innerHTML=priceobj.bidprice;

},
datatype:'jsonp'
</script>

I was told that it has to be jsonp, and not json (because I'm using an external url source).

Is it possible to use JSONP just from Jquery+HTML+javascript to embed prices in plain text?

If not Bitstamp's api can I use BitcoinChart's, or Blockchain's API?

telepatheic
Jr. Member
*
Offline Offline

Activity: 56
Merit: 1


View Profile
May 01, 2014, 02:35:28 PM
 #2

To get around the same origin policy you need to make an HTTP header with:

Code:
Access-Control-Allow-Origin: https://www.bitstamp.net

See http://en.wikipedia.org/wiki/Cross-origin_resource_sharing

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!