2017-12-17 1 views
1

나는 카르타노 코인을 위해 가격 체커를 만들고 싶었고 일반적인 API와 함께 작동합니다. https://api.coinmarketcap.com/v1/ticker/.PHP로 코인 마켓 작업의 API를 얻을 수 없습니다

하지만 다른 동전의 정보가 필요 없기 때문에이 API를 사용하고 싶습니다. https://api.coinmarketcap.com/v1/ticker/cardano.

내가 처음에 사용되는 코드 :

<!DOCTYPE html> 
<html> 
    <head> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
    <title id="title"></title> 
    </head> 
    <table> 
    <tr> 
     <th>Cardano</th> 
    </tr> 
    <tr> 
     <td id="cardano"></td> 
    </tr> 
    </table> 

<script> 
$.get("https://api.coinmarketcap.com/v1/ticker/", function(data, status) { 
    for (var i = 0; i < data.length - 1; i++) { 
    if (data[i].id == "cardano") { 
     $("#title").html(data[i].price_usd); 
     $("#cardano").html(data[i].price_usd); 
    } 
    } 
}); 
</script> 
</body> 
</html> 

그것은 다른 API를 변경하기 정말 쉬운 것 같다하지만 난 그냥 일을 얻을 수 없습니다. 두 번째에 대한

내 코드 : 나를 위해

<script> 
$.get("https://api.coinmarketcap.com/v1/ticker/cardano", function(data, status) { 
     $("#title").html(data[0].price_usd); 
     $("#cardano").html(data[0].price_usd); 
}); 
</script> 

답변

0
$.get("https://api.coinmarketcap.com/v1/ticker/cardano/", function(data, status) { 
    $("#title").html(data[0].price_usd); 
    $("#cardano").html(data[0].price_usd); 
}); 

작품, 그냥 /로 URL을 마무리. 웹 서버의 일부 리디렉션 규칙 때문에 최종 슬래시가 작동하지 않는다고 생각합니다.

Bytheway은 첫 번째 예는 더 경우 조건 안에 체류 최적화된다 :

$.get("https://api.coinmarketcap.com/v1/ticker/", function(data, status) { 
    for (var i = 0; i < data.length - 1; i++) { 
    if (data[i].id == "cardano") { 
     $("#title").html(data[i].price_usd); 
     $("#cardano").html(data[i].price_usd); 
     break; 
    } 
    } 
}); 

이 방법은 정지를위한 상기 카르 다노 ID가 발견되는 경우.

+0

감사합니다. 나는 /이 그렇게 중요하다는 것을 몰랐다.! –

+0

일반적으로 서버가 잘못 구성된 경우에만 그렇지 않습니다. 문제가 해결 되었다면 답을 올바른 것으로 표시하면 감사하겠습니다. – jeprubio

관련 문제