Thắng Trương
Bạn có muốn phản ứng với tin nhắn này? Vui lòng đăng ký diễn đàn trong một vài cú nhấp chuột hoặc đăng nhập để tiếp tục.

Go down
avatar
Admin
Admin
Tổng số bài gửi : 1562
Join date : 20/05/2018
https://thangcrm2.forumvi.com

[Javascript] RESTfull API coinmarketcap Empty [Javascript] RESTfull API coinmarketcap

Sun May 20, 2018 4:39 pm
Code:
<html>

<head>
    <title>Bootstrap Example</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>
    <link rel="stylesheet" href="html.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>

<body style="word-wrap: break-word;">
    <div class="container">
        <table class="table">
            <thead>
                <tr>
                    <th width="25%">
                        <center>Name: </center>
                    </th>
                    <th width="25%">
                        <center>USD: </center>
                    </th>
                    <th width="25%">
                        <center>BTC: </center>
                    </th>
                    <th width="25%">
                        <center>MarketCap: </center>
                    </th>
                </tr>
            </thead>
            <tbody>
            </tbody>
        </table>
    </div>
    <script>
        $(document).ready(function () {
            $.ajax({
                url: "https://api.coinmarketcap.com/v1/ticker/",
                type: "GET",
                dataType: "JSON",
                success: function (res) {
                    var i;
                    var x = 0;
                    for (i = 0; i > -1; i++) {
                        var text = "<tr><td><center>" +
                            res[x].name + "</center></td>" + "<td><center>" +
                            res[x].price_usd + "</center></td>" + "<td><center>" +
                            res[x].price_btc + "</center></td>" + "<td><center>" +
                            res[x].market_cap_usd + "</center></td>" + "</tr>";
                        $("tbody").append(text);
                        $(".TextBox").show();
                        x = x + 1;
                    }
                },
                error: function () {
                    alert("fail");
                },
            });

            setTimeout(function () {
                window.location.reload(1);
            }, 5000);
        })
    </script>
</body>

</html>
Về Đầu Trang
Permissions in this forum:
Bạn không có quyền trả lời bài viết