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

6
  • Probably due to the same origin policy. Are you on the same domain as the data you are requesting? Commented Mar 13, 2013 at 11:44
  • What is the error message you are getting in the second? Commented Mar 13, 2013 at 11:45
  • try this link Commented Mar 13, 2013 at 11:45
  • No, not on the same domain. But can we do this using c#. I tried GetResponse() Method of c# but the request timed out. Commented Mar 13, 2013 at 11:45
  • So you want to make a proxy in C# that makes the call on your behalf, via a JavaScript call to a web service? Commented Mar 13, 2013 at 11:46

4 Answers 4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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})
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.

Comments

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.

2 Comments

but how to get the data from mtgox web-service. That standsout a the main question.
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.
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.