当我使用带有sAjaxSource的DataTables时,它可以工作,但是在预先执行ajax并设置aaData属性时,我会收到错误。有什么想法吗?
此方法有效:
// This method works fine
$('#spiderData').dataTable({
"bProcessing": true,
"sAjaxSource": "spiderOrders.cshtml?GetOrders=true&pid=" + pid + "&itemid=" + itemId + "&signatur=" + signatur + "&orderid=" + orderid + "&type=signatur",
"aoColumns": [
{ "mDataProp": "BuildOrderId" },
{ "mDataProp": "description" },
{ "mDataProp": "BuildProductOrderId" },
{ "mDataProp": "state_desc" },
{ "mDataProp": "buildProductName" },
{ "mDataProp": "program" },
{ "mDataProp": "KP_BPO" },
{ "mDataProp": "WorkOrderId" },
{ "mDataProp": "title" },
{ "mDataProp": "state_desc" },
{ "mDataProp": "contractorName" },
{ "mDataProp": "TP" }
]
});
但这不是:
// This is not working, why????
$.ajax({
type: 'GET',
url: "spiderOrders.cshtml?GetOrders=true&pid=" + pid + "&itemid=" + itemId + "&signatur=" + signatur + "&orderid=" + orderid + "&type=signatur",
data: "jalla",
success: function (data) {
$('#spiderData').dataTable({
"bProcessing": true,
"aaData": data,
"aoColumns": [
{ "mDataProp": "BuildOrderId" },
{ "mDataProp": "description" },
{ "mDataProp": "BuildProductOrderId" },
{ "mDataProp": "state_desc" },
{ "mDataProp": "buildProductName" },
{ "mDataProp": "program" },
{ "mDataProp": "KP_BPO" },
{ "mDataProp": "WorkOrderId" },
{ "mDataProp": "title" },
{ "mDataProp": "state_desc" },
{ "mDataProp": "contractorName" },
{ "mDataProp": "TP" }
]
});
}
});
如果第一个示例返回的数据具有以下格式:
{ "aaData": [
{
"BuildOrderId":"S2008-015758.001",
"description":"Hordaland-Bergen-ALH4 - Leveranse av 2 Mb",
"BuildProductOrderId":"S2008-015758.002", .....
在第二个例子中这种格式:
[{"BuildOrderId":"S2008-006891.001","description":"MXJP81, BERSTADHUSETMOB, HOR-00323","BuildProductOrderId":"S2008-006891.002", ....
我是否遗漏了某些内容,或者错误地将回复格式化了(我现在已经检查了几次......)
答案 0 :(得分:3)
为什么第二种方式很重要?如果您需要访问.ajax提供的所有内容(变量与默认.getJSON相比更具灵活性),您仍然可以使用fnServerData参数执行此操作。
那就是说,第二种方式可能出错的是你试图直接使用“数据”。它需要先解析。
"aaData": $.parseJSON(data).aaData,
免责声明:我没有测试过这个并且更喜欢fnServerData方法