我尝试执行此程序,但未得到任何输出

时间:2018-12-20 17:25:19

标签: javascript html ajax

要解析json数据并推送到HTML      HTML

<!DOCTYPE html>       
<html>
<head>
<title>JSON data to html table using Ajaz Jquery getJSON method
</tiltle>
 <script 
  src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"> 
 </script>
<link rel = "stylesheet"  href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"/>
<script src `enter code 
here`="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"> 
</script>
</head>
<body>
  <div class="container">
    <div class="table-responsive">
      <h1>JSON data to html table using ajax jquery getJason method</h1>
       <br/>
     <table class="table bordered and striped" id="employee_table">
       <tr>
           <th>ID</th>
           <th>Name</th>
       </tr>
     </table>
     </div>
     </div>
     </body>
     </html>

 Java Script: 
 <script>

 $(document).ready(function(){
 $.getJSON("C:\Users\RS******\Documents\json  
   work\employee1.json",function(data){
    var employee_data = '';
    $.each(data,function(key,value){
        employee_data += '<tr>';
        employee_data += '<td>'+value.id+'</td>';
        employee_data += '<td>'+value.name+'</td>';
        employee_data += '</tr>';
    });
    $('employee_table').append(employee_data);
    });
   });
  </script>

JSON:
my employee1.json file:
[
  {
    "id":"1",
    "name":"john smith",
    "address":"kansas "

   }
 ]

实际上必须使用哪个编辑器才能执行html javascript文件,并且当我们从api获取数据时,我们应该如何使用ajax在javascript中从其余api解析数据并以html显示。

0 个答案:

没有答案