Bitcoin Forum
December 09, 2016, 09:24:15 PM *
News: Latest stable version of Bitcoin Core: 0.13.1  [Torrent].
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: JQuery and mtgox ticker not playing nicely  (Read 2706 times)
tenbatsu
Newbie
*
Offline Offline

Activity: 7


View Profile
June 11, 2011, 06:52:53 AM
 #1

Any thoughts on why this fails?

Code:
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
  $.ajax({
    url: 'https://mtgox.com/code/data/ticker.php',
    dataType: 'jsonp',
    success: function(data){
      // Note: because of failure, not even trying to print out the ticker data at this point
      alert('foo');
    }
  });
});
</script>
</head>
<body>
</body>
</html>

In firefox 4.0.1, I get this error:

Code:
Error: invalid label
Source File: https://mtgox.com/code/data/ticker.php?callback=jQuery1610765425372311095_1307774805819&_=1307774805835
Line: 1, Column: 1
Source Code:
{"ticker":{"high":28.601,"low":20.01,"vol":98283,"buy":21.751,"sell":21.8156,"last":21.8158}}

In chrome 12.0.742.91, I get these errors:

Code:
ticker.php: -1Resource interpreted as Script but transferred with MIME type text/html.
ticker.php: 1Uncaught SyntaxError: Unexpected token :
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
Maged
Legendary
*
Offline Offline

Activity: 1260


View Profile
June 11, 2011, 07:33:31 AM
 #2

dataType: 'jsonp'

The dataType should just be 'json', since that's all your getting back. Besides, unless you control the server giving you the data, you shouldn't use jsonp.

tenbatsu
Newbie
*
Offline Offline

Activity: 7


View Profile
June 11, 2011, 07:39:35 AM
 #3

But it -is- cross domain, so json isn't an option, right?

Firefox gives neither an error nor the javascript alert and chrome fails as expected with the following:

Code:
XMLHttpRequest cannot load https://mtgox.com/code/data/ticker.php. Origin http://[___MY_SITE___] is not allowed by Access-Control-Allow-Origin.
Maged
Legendary
*
Offline Offline

Activity: 1260


View Profile
June 11, 2011, 08:03:29 AM
 #4

But it -is- cross domain, so json isn't an option, right?

Firefox gives neither an error nor the javascript alert and chrome fails as expected with the following:

Code:
XMLHttpRequest cannot load https://mtgox.com/code/data/ticker.php. Origin http://[___MY_SITE___] is not allowed by Access-Control-Allow-Origin.
That actually depends on the site. That said, it appears that MtGox supports neither CORS or JSONP. You'll have to ask him about it.

In the mean time, that means that you'll have to have your server grab the data and act as a proxy.

tenbatsu
Newbie
*
Offline Offline

Activity: 7


View Profile
June 11, 2011, 08:06:50 AM
 #5

Quote
In the mean time, that means that you'll have to have your server grab the data and act as a proxy.

Darn, I was hoping to avoid that.  Ah well.

Thank you for your help!
lego
Newbie
*
Offline Offline

Activity: 3


View Profile
June 11, 2011, 08:43:48 AM
 #6

Your best bet would be to cache the ticker to your server at certain intervals and query that as json. Undecided
eturnerx
Member
**
Offline Offline

Activity: 70


View Profile WWW
June 11, 2011, 10:15:03 AM
 #7

I had a similar problem - so had to create a proxy script to run on my server. Pretty easy to do actually.

WatchMine - get Bitcoin prices and pool stats on your Mobile
tenbatsu
Newbie
*
Offline Offline

Activity: 7


View Profile
June 11, 2011, 10:18:55 AM
 #8

Easy, yes, but I have neither a reliable server nor a reliable IP.  I was hoping to rely on mtgox.
eturnerx
Member
**
Offline Offline

Activity: 70


View Profile WWW
June 11, 2011, 02:56:19 PM
 #9

MTGox has a websockets interface that you might be able to use instead.
http://websocket.org/ - THe official website
http://caniuse.com/#feat=websockets - Lookup browser support


WatchMine - get Bitcoin prices and pool stats on your Mobile
molecular
Donator
Legendary
*
Offline Offline

Activity: 2142



View Profile
June 12, 2011, 10:26:00 AM
 #10

MTGox has a websockets interface that you might be able to use instead.
http://websocket.org/ - THe official website
http://caniuse.com/#feat=websockets - Lookup browser support



here's the forum topic with lots of info (also on the currently existing bugs):

http://forum.bitcoin.org/index.php?topic=5855.0

PGP key molecular F9B70769 fingerprint 9CDD C0D3 20F8 279F 6BE0  3F39 FC49 2362 F9B7 0769
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!