如何将JSON从URL解析为HTML表

时间:2019-02-15 17:10:17

标签: javascript html json

这是我编写时的代码。它看起来正确,但不会从给定的URL进行解析。 (This Link)我只是想解析“ Location”和“ Name”变量。谁能告诉我我在做什么错?

 <html>
    <head>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"> </script>

    <script>

        $(function() {


       var assets = [];

       $.getJSON('https://api.samsara.com/v1/fleet/assets/locations?access_token=MrK3UCw9vu2a5HlCa2n6dOogyYtPcX', function(data) {
           $.each(data.assets, function(i, f) {
              var tblRow = "<tr>" + "<td>" + f.location + "</td>" +
               "<td>" + f.name + "</td>" + "</tr>"
               $(tblRow).appendTo("#userdata tbody");
         });

       });

    });
    </script>
    </head>

    <body>

    <div class="wrapper">
    <div class="profile">
       <table id= "userdata">
      <thead>
                <th>Location</th>
                <th>Name</th>

            </thead>
          <tbody>

           </tbody>
       </table>

    </div>
    </div>

    </body>
    </html>

0 个答案:

没有答案