为第 0 行请求了未知参数 'ASSET_NAME'
Requested unknown parameter 'ASSET_NAME' for row 0
我正在尝试从 AJAX 创建数据表,但仍然出现错误
Requested unknown parameter 'ASSET_NAME' for row 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>
我尝试了很多组合,但都没有成功。
那里出了什么问题?
谢谢
雷迪
您将 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"}]'),
我正在尝试从 AJAX 创建数据表,但仍然出现错误
Requested unknown parameter 'ASSET_NAME' for row 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>
我尝试了很多组合,但都没有成功。
那里出了什么问题?
谢谢 雷迪
您将 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"}]'),