Bitcoin Forum
March 19, 2024, 03:34:15 AM *
News: Latest Bitcoin Core release: 26.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: JQuery and mtgox ticker not playing nicely  (Read 2989 times)
tenbatsu (OP)
Newbie
*
Offline Offline

Activity: 7
Merit: 0


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 :
1710819255
Hero Member
*
Offline Offline

Posts: 1710819255

View Profile Personal Message (Offline)

Ignore
1710819255
Reply with quote  #2

1710819255
Report to moderator
"There should not be any signed int. If you've found a signed int somewhere, please tell me (within the next 25 years please) and I'll change it to unsigned int." -- Satoshi
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1710819255
Hero Member
*
Offline Offline

Posts: 1710819255

View Profile Personal Message (Offline)

Ignore
1710819255
Reply with quote  #2

1710819255
Report to moderator
Maged
Legendary
*
Offline Offline

Activity: 1204
Merit: 1015


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 (OP)
Newbie
*
Offline Offline

Activity: 7
Merit: 0


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: 1204
Merit: 1015


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 (OP)
Newbie
*
Offline Offline

Activity: 7
Merit: 0


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
Merit: 0


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: 84
Merit: 10


View Profile
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.
tenbatsu (OP)
Newbie
*
Offline Offline

Activity: 7
Merit: 0


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: 84
Merit: 10


View Profile
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

molecular
Donator
Legendary
*
Offline Offline

Activity: 2772
Merit: 1019



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:  

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