0

I have the following API which returns json data as follows:

API : http://data.mtgox.com/api/1/BTCUSD/ticker JSON : {"result":"success","return":{"high":.......

using jquery i tried the following but it is not giving me the data.

$.getJSON('http://data.mtgox.com/api/1/BTCUSD/ticker', function (data) {
                                               alert(data);
                                           });

and

$.ajax({
                      type: 'GET',
                      url: 'http://data.mtgox.com/api/1/BTCUSD/ticker',
                      dataType: 'json',
                      success: function (data) {
                          alert(data);
                      },
                      error: function (error) {
                          alert(error + "error");
                      }
                  });

but in first i get no alert

and in second i get error alert.

How can I read this data using jQUERY or C#?

THanks

vishal
  • 197
  • 5
  • 20

4 Answers4

1

As Archer mentioned this won't work if you're not on the same domain. There is one way around this using CORS (http://en.wikipedia.org/wiki/Cross-origin_resource_sharing) but you'd need to have control over the domain to set the required header or at least get the person in charge to do so.

The other option is to use JSONP which basically wraps the result in a function call that runs immediately when it returns by injecting a script tag. Problem is you lose nice things like error handling and you can't cancel the request.

Alkem1st
  • 41
  • 2
  • If you're trying via JSONP you still need access to the data as the JSON needs to be wrapped in a function. This function is the callback you specify when constructing your $.ajax call. E.g. `callback({"json":data})` – Alkem1st Mar 13 '13 at 14:31
0

I tried your problem. The error showed in Google Chrome Javascript Console was Origin http://localhost:1564 is not allowed by Access-Control-Allow-Origin

Check the answer to this Question and find your way out.

Community
  • 1
  • 1
Subin Jacob
  • 4,692
  • 10
  • 37
  • 69
0

Is live data required ? Like "I must see the data as current as from this exact second" ?

If not (probably that is the case), I suggest you make a scheduled process (let's say every 5 min) on the web server. That will get data from the source (http://data.mtgox.com) and put it into database table.

After that you make your own JSON service (an MVC action method) and publish the data from your tables.

It will also allow your customers that your site is working even if mtgox.com is down for some reason.

pero
  • 4,169
  • 26
  • 27
  • but how to get the data from mtgox web-service. That standsout a the main question. – vishal Mar 13 '13 at 12:12
  • You have problem to do it from client browser. From web server there are no obstacles. The problem is that JavaScript that is executing on the browser is allowed to request resources only from domain from where the page came from. And your page did not come to the browser from mtgox.com. – pero Mar 13 '13 at 12:15
0

How to getting Data through web Services with jquery in asp.net c#. for more details http://way2finder.blogspot.in/2013/08/how-to-getting-data-through-web.html

Jquery
  • 67
  • 1
  • 2