Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用jquery datatable显示url中的API数据_Jquery_Ajax_Api_Url_Datatables - Fatal编程技术网

如何使用jquery datatable显示url中的API数据

如何使用jquery datatable显示url中的API数据,jquery,ajax,api,url,datatables,Jquery,Ajax,Api,Url,Datatables,我正在为我的FiveM服务器网站设置一个“统计”页面,我需要关于如何使用Jquery Datatables显示数据的帮助 <table id="table_id" class="display"> <thead> <tr> <th>Votes</th> <th>Player Name</th> </tr>

我正在为我的FiveM服务器网站设置一个“统计”页面,我需要关于如何使用Jquery Datatables显示数据的帮助

<table id="table_id" class="display">
    <thead>
        <tr>
            <th>Votes</th>
            <th>Player Name</th>
        </tr>
    </thead>
    <tbody>
        <!-- data -->
    </tbody>
</table>


<script type="text/javascript">
$(document).ready( function () {

    $.ajax({
        url : 'https://api.top-serveurs.net/v1/servers/SC4VCSEUS3/players-ranking',
        type : 'GET',
        dataType : 'json',
        success : function(data) {
            bindtoDatatable(data.players);
        }
    });



});

function bindtoDatatable(data) {
        var table = $('#table_id').dataTable({
            "bAutoWidth" : false,
            "aaData" : data,
            "columns" : [ {
                "data" : "votes"
            }, {
                "data" : "playername"
            } ]
        })
    }
</script>
我对API一无所知,所以我用PHP尝试了一些东西,但没有什么真正有用的:/

<table id="table_id" class="display">
    <thead>
        <tr>
            <th>Votes</th>
            <th>Player Name</th>
        </tr>
    </thead>
    <tbody>
        <!-- data -->
    </tbody>
</table>


<script type="text/javascript">
$(document).ready( function () {

    $.ajax({
        url : 'https://api.top-serveurs.net/v1/servers/SC4VCSEUS3/players-ranking',
        type : 'GET',
        dataType : 'json',
        success : function(data) {
            bindtoDatatable(data.players);
        }
    });



});

function bindtoDatatable(data) {
        var table = $('#table_id').dataTable({
            "bAutoWidth" : false,
            "aaData" : data,
            "columns" : [ {
                "data" : "votes"
            }, {
                "data" : "playername"
            } ]
        })
    }
</script>
这是我的密码:

<table id="table_id" class="display">
    <thead>
        <tr>
            <th>Votes</th>
            <th>Player Name</th>
        </tr>
    </thead>
    <tbody>
        <!-- data -->
    </tbody>
</table>


<script type="text/javascript">
$(document).ready( function () {

    $.ajax({
        url : 'https://api.top-serveurs.net/v1/servers/SC4VCSEUS3/players-ranking',
        type : 'GET',
        dataType : 'json',
        success : function(data) {
            bindtoDatatable(data.players);
        }
    });



});

function bindtoDatatable(data) {
        var table = $('#table_id').dataTable({
            "bAutoWidth" : false,
            "aaData" : data,
            "columns" : [ {
                "data" : "votes"
            }, {
                "data" : "playername"
            } ]
        })
    }
</script>

测试阿斯托斯
第1栏
第2栏
$(文档).ready(函数(){
$('#表_id')。数据表({
$.ajax({
网址:'https://api.top-serveurs.net/v1/servers/SC4VCSEUS3/players-ranking',
键入:“GET”,
数据类型:“json”,
成功:函数(json,statut){//code\u html contient le html renvoyé
}
});
});
});
我想用jquerydatatables显示这些数据()

<table id="table_id" class="display">
    <thead>
        <tr>
            <th>Votes</th>
            <th>Player Name</th>
        </tr>
    </thead>
    <tbody>
        <!-- data -->
    </tbody>
</table>


<script type="text/javascript">
$(document).ready( function () {

    $.ajax({
        url : 'https://api.top-serveurs.net/v1/servers/SC4VCSEUS3/players-ranking',
        type : 'GET',
        dataType : 'json',
        success : function(data) {
            bindtoDatatable(data.players);
        }
    });



});

function bindtoDatatable(data) {
        var table = $('#table_id').dataTable({
            "bAutoWidth" : false,
            "aaData" : data,
            "columns" : [ {
                "data" : "votes"
            }, {
                "data" : "playername"
            } ]
        })
    }
</script>

谢谢:)。

首先,您忘记使用jQuery CDN,请参见示例中的内容。像这样使用。
<table id="table_id" class="display">
    <thead>
        <tr>
            <th>Votes</th>
            <th>Player Name</th>
        </tr>
    </thead>
    <tbody>
        <!-- data -->
    </tbody>
</table>


<script type="text/javascript">
$(document).ready( function () {

    $.ajax({
        url : 'https://api.top-serveurs.net/v1/servers/SC4VCSEUS3/players-ranking',
        type : 'GET',
        dataType : 'json',
        success : function(data) {
            bindtoDatatable(data.players);
        }
    });



});

function bindtoDatatable(data) {
        var table = $('#table_id').dataTable({
            "bAutoWidth" : false,
            "aaData" : data,
            "columns" : [ {
                "data" : "votes"
            }, {
                "data" : "playername"
            } ]
        })
    }
</script>

<table id="table_id" class="display">
    <thead>
        <tr>
            <th>Votes</th>
            <th>Player Name</th>
        </tr>
    </thead>
    <tbody>
        <!-- data -->
    </tbody>
</table>


<script type="text/javascript">
$(document).ready( function () {

    $.ajax({
        url : 'https://api.top-serveurs.net/v1/servers/SC4VCSEUS3/players-ranking',
        type : 'GET',
        dataType : 'json',
        success : function(data) {
            bindtoDatatable(data.players);
        }
    });



});

function bindtoDatatable(data) {
        var table = $('#table_id').dataTable({
            "bAutoWidth" : false,
            "aaData" : data,
            "columns" : [ {
                "data" : "votes"
            }, {
                "data" : "playername"
            } ]
        })
    }
</script>

投票
球员姓名
$(文档).ready(函数(){
$.ajax({
网址:'https://api.top-serveurs.net/v1/servers/SC4VCSEUS3/players-ranking',
键入:“GET”,
数据类型:“json”,
成功:功能(数据){
bindtoDatatable(data.players);
}
});
});
函数bindtoDatatable(数据){
var table=$('#table_id')。数据表({
“bAutoWidth”:假,
“aaData”:数据,
“列”:[{
“数据”:“投票”
}, {
“数据”:“玩家名称”
} ]
})
}

谢谢,它很管用!我觉得很难,非常感谢!虽然这样做有效,但这种方法并不理想-您不应使用外部ajax调用来填充表,为此有一个本机的
ajax
选项-它提供了更好的性能(对于动态应用程序,上述方法将要求销毁/重新创建数据表,或清除/重新填充其内容)并与其他DataTables API方法集成。