小编dee*_*thy的帖子

ajax 中的 JSON 到 HTML 表

这是我拥有的 JSON

{
   "version": "5.2",
   "user_type": "online",
   "user":
   [
       {
            "name": "John",
            "id": 50
       },
       {
            "name": "Mark",
            "id": 57
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

将上述 JSON 转换为 HTML 的 javascript

<script type="text/javascript">
$(document).ready(function(){
    $.ajax({
        url: "http://PATH/user.json",
        dataType: 'json',
        type: 'get',
        cache:false,
        success: function(data){
            /*console.log(data);*/
            var event_data = '';
            $.each(data, function(index, value){
                /*console.log(value);*/
                event_data += '<tr>';
                event_data += '<td>'+value.name+'</td>';
                event_data += '<td>'+value.id+'</td>';
                event_data += '<tr>';
            });
            $("#list_table_json").append(event_data);
        },
        error: function(d){
            /*console.log("error");*/
            alert("404. Please wait until the File is Loaded.");
        }
    });
}); …
Run Code Online (Sandbox Code Playgroud)

html javascript ajax jquery json

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

ajax ×1

html ×1

javascript ×1

jquery ×1

json ×1