vishal
vishal

Reputation: 207

read Json data from a webservice using jQuery or C#

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

Upvotes: 0

Views: 904

Answers (4)

Jquery
Jquery

Reputation: 67

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

Upvotes: 0

pero
pero

Reputation: 4259

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.

Upvotes: 0

Subin Jacob
Subin Jacob

Reputation: 4864

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.

Upvotes: 0

Alkem1st
Alkem1st

Reputation: 41

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.

Upvotes: 1

Related Questions