Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

jquery datatable rest api

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
    <link href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" rel="stylesheet" />
    
</head>
<body>
    <table id="tableSwapi" class="table table-striped">
        <thead>
            <tr>
                <th>Name</th>
                <th>Rotation Period</th>
                <th>Orbital Period</th>
                <th>Diameter</th>
                <th>Climate</th>
                <th>Gravity</th>
                <th>Terrain</th>
                <th>Water Surface</th>
                <th>Population</th>
            </tr>
        </thead>
        <tbody id="list-list"></tbody>
    </table>    
    <script
  src="http://code.jquery.com/jquery-3.3.1.min.js"
  integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
  crossorigin="anonymous"></script>
    <script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
    
    <script>
        $(document).ready(function () {
            $("#tableSwapi").dataTable();

            $.ajax({
                url: 'https://swapi.co/api/planets/',
                type: 'get',
                dataType: 'json',
                success: function (result) {
                    let daftar = result.results;
                    var html = '';
                    $.each(daftar, function (i, data) {
                        html += `<tr>
                                        <td> ` + data.name + `</td>
                                        <td>` + data.rotation_period + `</td>
                                        <td>` + data.orbital_period + `</td>
                                        <td>` + data.diameter + `</td>
                                        <td> ` + data.climate + ` </td>
                                        <td> ` + data.gravity + ` </td>
                                        <td>` + data.terrain + `</td>
                                        <td> ` + data.surface_water + `</td>
                                        <td> ` + data.population + ` <br></td>
                                    </tr>`;

                        //This is selector of my <tbody> in my table
                        $("#list-list").html(html);
                    });
                }
            });
        })


    </script>
</body>
</html>
 Run code snippet
Comment

PREVIOUS NEXT
Code Example
Javascript :: build#configuring-commonjs-dependencie - angular.json 
Javascript :: how to enable emit on react in vs code 
Javascript :: discord.js presence update 
Javascript :: babel-polyfill whatwg-fetch 
Javascript :: javascript slice 
Javascript :: validate form on submit 
Javascript :: how to set default value in input field in angularjs 
Javascript :: javascript get character from string 
Javascript :: react-native-google-places-autocomplete only cities 
Javascript :: how to export module in node js 
Javascript :: reload parent window from prompt 
Javascript :: how to increment variable value in javascript 
Javascript :: ajax is not a function 
Javascript :: javascript var,let,const compare 
Javascript :: js convert string to date 
Javascript :: object check null or empty 
Javascript :: java script strict tag 
Javascript :: lodash find duplicate element index 
Javascript :: object copy in javascript 
Javascript :: currentTime(); javascript 
Javascript :: local reload go to top 
Javascript :: system navigation bar react native 
Javascript :: get all a elements javascript 
Javascript :: cheerio 
Javascript :: validar array vacio javascript 
Javascript :: jquery add br in text 
Javascript :: Angular empty object 
Javascript :: load more button javascript 
Javascript :: get before 6 month date javascript node js 
Javascript :: javascript how to deal with %20 in string 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =