将API数据从XML链接中提取到HTML页面中

时间:2019-08-02 20:51:07

标签: html xml api

如何将API数据从XML链接提取到HTML页面? 这是我从中获取的链接。 www.bitinka.com/api/apinka/ticker/ETH_USD

我只想获取有关lastPrice的信息。我是编码的新手,我尝试了不同的方式,但对我来说没有任何用。我知道我在掌握到目前为止所学的知识,但是我在做什么错呢?如果需要,我是否需要创建一个新的javascript?以及如何使它起作用? 我想使用html将信息拉入一个小盒子 这是xml链接信息

<xml>
<ETH>
<item>
<symbol>ETH_USD</symbol>
<volumen24hours>122.07221062</volumen24hours>
<ask>235.70000000</ask>
<bid>220.00000000</bid>
<lastPrice>216.80776751</lastPrice>
</item>
</ETH>
</xml> 

我当前的代码如下。

<head>
<title>The Ticker price</title>
<style>
    #container{
        width: 270px;
        height: 90px;
        border: 1px solid #000;
        background-color: #2f2f2f;
        overflow: hidden;
        border-radius: 3px;
        color: #fefdfb    
    }
    #lastPrice{
        font-size: 30px;
        color: #ffffff;
    }
</style>

<script type="text/javascript" src="https://code.jquery.com/jquery- 1.12.1.min.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
            $.ajax({
                type: "GET",
                url: "https://www.bitinka.com/api/apinka/ticker/ETH_USD",
                datatype:"xml",
                success: xmlParser    
            });
        });
        }
</script>
</head>
<body>
<p>1 ETH = </p><div id="container">
<div class="lastPrice"></div></div>  
</body>

0 个答案:

没有答案