2017-09-18 33 views
0

任何人都可以幫助我如何從cryptocompare api獲取數據嗎? 我不知道我錯了什麼,但下面的代碼不起作用。 我在這個例子中使用jquery-1.10.2。 從cryptocompare JSON的看起來像這樣:getJSON不能與cryptocompare api一起使用

{ 「響應」: 「錯誤」, 「消息」: 「」, 「類型」:1, 「聚合」:假, 「數據」: [], 「路徑」: 「/數據/」, 「ErrorsSummary」: 「未實現」 }

var jqxhr = $.getJSON("https://min-api.cryptocompare.com/data/", {}, 

function(data) { 
    console.log("success : " + data); 
}).fail(function(jqxhr, status, error) { 
    console.log("error :" + error); 
}).always(function() { 
    console.log("complete"); 
}); 
}); 

預先感謝您。

回答

0

我只是更改$.getJSONURL,我刪除了https:,它可以按照您的要求工作。如果你不寫https: or http:那麼它是自動考慮。

var jqxhr = $.getJSON("//min-api.cryptocompare.com/data/", {}, 
 

 
function(data) { 
 
    debugger; 
 
    console.log(data); 
 
}).fail(function(jqxhr, status, error) { 
 
    console.log("error :" + error); 
 
}).always(function() { 
 
    console.log("complete"); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

+0

感謝您的幫助,但這不適用於我的網頁。我的服務器可能有問題嗎?我的網頁是http://reffey.nl/coints/coints.php –

+0

因爲你是從'http'服務器調用'https'。 –

+0

我將我的服務器更新到了https,我很抱歉地說它仍然不起作用。你能告訴我是否有什麼我做錯了嗎? –

0

但你的JSON的網址是錯誤的。

https://min-api.cryptocompare.com/

,我嘗試一個樣本JSON。

var jqxhr = $.getJSON("https://min-api.cryptocompare.com/data/histominute?fsym=BTC&tsym=USD&limit=60&aggregate=3&e=CCCAGG", {}, 

function(data) { 
    console.log("success : " +JSON.stringify(data)); 
}).fail(function(jqxhr, status, error) { 
    console.log("error :" + error); 
}).always(function() { 
    console.log("complete"); 
}); 

Jsfiddle查看控制檯。

相關問題