本文共 1505 字,大约阅读时间需要 5 分钟。
这是调用webapi后将数据赋给datatables的js代码,被注释的部分调用失败。
下面是webapi获取到的数据[{"Name":"主电室","Address":"江苏省苏州市苏州工业园区","Project":6300611,"ResourceID":8632006310,"Location":"120.3889,32.772462","Type":"powerdistribution", }]
下面是js调用代码function setStation(id) { $.ajax({ type: 'GET', url: apiurl + 'api/Station', //contentType: "application/json; charset=utf-8", data: { id: id, }, async: false, dataType: "json", success: function (data) { console.log(data) var data1 = JSON.parse(data) console.log(data1) $('#tableStation').DataTable({ data: data1, columns: [ { data: 'Name' }, { data: 'Address' }, { data: 'Type' }, { data: 'Location' } ], "destroy": true, }); }, error: function (message) { // alert(message); } }); //$('#tableStation').DataTable({ // "ajax": { // "url": apiurl + "api/Station/" + id, // "type": "GET", // "dataType": "json", // //"success": function (json) { // //}, // "dataSrc": function (result) { // } // }, // "columns": [ // { "data": "name" }, // { "data": "Address" }, // { "data": "Type" }, // { "data": "Location" }, // ], // "destroy": true, //});}
转载地址:http://xmumf.baihongyu.com/