我正在尝试从AJAX创建一个数据表,但仍然出现错误
请求的未知参数' ASSET_NAME'第0行。
即使JSON格式正确(由http://www.jslint.com/验证),列列表与JSON源中的引用列相同:
$(document).ready(function() {
$('#auditResults').dataTable( {
"aaData": '[{"ASSET_NAME":"CVCMAgent","a1_hostname":"czcholsint1027.prg-dc.dhl.com","a1_port":"5000","a1_asset_version":"1.6","a1_build":"1504130525"},
{"ASSET_NAME":"CVCMAgent","a1_hostname":"czcholsint1027.prg-dc.dhl.com","a1_port":"6000","a1_asset_version":"1.6","a1_build":"1504130525"}]',
"aoColumns": [
{"sTitle": "ASSET_NAME", "mData": "ASSET_NAME"} , {"sTitle": "a1_hostname", "mData": "a1_hostname"} , {"sTitle": "a1_port", "mData": "a1_port"} , {"sTitle": "a1_asset_version", "mData": "a1_asset_version"} , {"sTitle": "a1_build", "mData": "a1_build"}
]
} );
} );

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<table id="auditResults" name="auditResults" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>ASSET_NAME</th>
<th>a1_hostname</th>
<th>a1_port</th>
<th>a1_asset_version</th>
<th>a1_build</th>
</tr>
</thead>
</table>
&#13;
我尝试了很多组合但没有任何成功。
那里出了什么问题?
由于 雷迪
答案 0 :(得分:0)
您将JSON作为字符串传递,您应该将其作为JSON传递:
"aaData": [{"ASSET_NAME":"CVCMAgent","a1_hostname":"czcholsint1027.prg-dc.dhl.com","a1_port":"5000","a1_asset_version":"1.6","a1_build":"1504130525"},{"ASSET_NAME":"CVCMAgent","a1_hostname":"czcholsint1027.prg-dc.dhl.com","a1_port":"6000","a1_asset_version":"1.6","a1_build":"1504130525"}]',
如果您因任何原因无法做到这一点,可以使用JSON.parse()
:
"aaData": JSON.parse('[{"ASSET_NAME":"CVCMAgent","a1_hostname":"czcholsint1027.prgdc.dhl.com","a1_port":"5000","a1_asset_version":"1.6","a1_build":"1504130525"}, {"ASSET_NAME":"CVCMAgent","a1_hostname":"czcholsint1027.prgdc.dhl.com","a1_port":"6000","a1_asset_version":"1.6","a1_build":"1504130525"}]'),
参见 - &gt; http://jsfiddle.net/7ng9wfak/412/