Jimit
Jimit

Reputation: 245

unable to fetch json data using the jquery.getJSON()

I am trying to get the json data from the following link http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=132. It should provide me with following json data (some portion of data is displayed.

{
"success": 1,
"return": {
"markets": {
  "DOGE": {
    "marketid": "132",
    "label": "DOGE\/BTC",
    "lasttradeprice": "0.00000194",
    "volume": "862686257.04978180",
    "lasttradetime": "2014-02-24 03:26:52",
    "primaryname": "Dogecoin",
    "primarycode": "DOGE",
    "secondaryname": "BitCoin",
    "secondarycode": "BTC",
    "recenttrades": [
      {
        "id": "25951364",
        "time": "2014-02-24 03:37:59",
        "price": "0.00000195",
        "quantity": "41345.42127692",
        "total": "0.08062357"
      },
      {
        "id": "25951344",
        "time": "2014-02-24 03:37:34",
        "price": "0.00000194",
        "quantity": "469263.63233043",
        "total": "0.91037145"
      },
      {
        "id": "25951238",
        "time": "2014-02-24 03:36:51",
        "price": "0.00000194",
        "quantity": "8312.99451077",
        "total": "0.01612721"
      },

I have used the following code in the jquery to fetch the data

$(document).ready(function() {
     var url =  "http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=132";
     $.getJSON(url,function(data) {
     console.log(data);
   });
});

I am able to get the json data using the python but with jquery I am not getting the json object . Am I missing anything here ?

Upvotes: 0

Views: 155

Answers (2)

rahulroy9202
rahulroy9202

Reputation: 2848

Cross Domain Access might be the cause of your problem. Are you invoking this while on a different domain?

Take a look at the following questions:

Ways to circumvent the same-origin policy

Upvotes: 0

Arun P Johny
Arun P Johny

Reputation: 388436

The basic problem is what you are trying to do is a Same Origin Policy violation

It does not looks like the API is either supporting CORS or jsonp so you can't use it in the client side using an ajax request.

A possible solution is to make your web sever act like a proxy and sent the ajax request to your server, then your sever makes a api request to the remote server and gets the response and forwards the response back to the client.

Upvotes: 4

Related Questions