【发布时间】:2014-08-21 03:46:34
【问题描述】:
我正在使用带有 ASP.NET 4.5 的 jquery 数据表 1.10。该代码在调试时没有问题。当我运行它时,它不会填充表中的数据并保留为空数据集。这个错误出现在 FireBug 中。
代码:
$('#dtGroups').dataTable({
"oLanguage": {
"sZeroRecords": "No records to display",
"sSearch": "Search "
},
"aLengthMenu": [[25, 50, 100, 150, 250, 500, -1], [25, 50, 100, 150, 250, 500, "All"]],
"iDisplayLength": 25,
"bSortClasses": false,
"bStateSave": false,
"bPaginate": true,
"bAutoWidth": false,
"bProcessing": true,
"bServerSide": true,
"bDestroy": true,
"bJQueryUI": false,
"sAjaxSource": "<%= ResolveUrl("~/Handler/GetData") %>",
"sPaginationType": "full_numbers",
"bDeferRender": true,
"fnServerParams": function (aoData) {
},
"aoColumnDefs": [
{
"bVisible": false,
"aTargets": [0]
},
{
"aTargets": [1],
"mData": null,
"mRender": function (data, type, row) {
var enc = encodeURI(row[1]);
return "<a href='SomePage.aspx?qs="+enc+"'>" + row[1] + "</a>";
}
}
],
"fnServerData": function (sSource, aoData, fnCallback) {
var jsonAOData = JSON.stringify(aoData);
$.ajax({
"dataType": 'json',
"contentType": "application/json; charset=utf-8",
"type": "POST",
"url": sSource,
"data": "{ jsonAOData : '" + jsonAOData + "' }",
"success":
function (result) {
var json = jQuery.parseJSON(result.d);
console.log(json);
fnCallback(JSON.parse(result.d))
},
"error":
function (XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest + ": Error: " + XMLHttpRequest.responseText + ", " + textStatus + ": " + errorThrown);
}
});
}
});
任何帮助将不胜感激。
【问题讨论】:
-
服务器端是否正确接收jsonAOData?我不明白为什么你
JSON.stringify(aoData)然后在"data": "{ jsonAOData : '" + jsonAOData + "' }"之后手动挂载一个字符串 -
是的。服务器端正确接收 jsonAOData。它在调试时工作。但是在没有调试的情况下运行会失败。
-
所以在运行时它仍然可以正确接收 jsonAOData?
-
是的。它仍然正确接收 jsonAOData。现在我收到一个新错误“TypeError: $.fn.dataTable is undefined”。
标签: javascript jquery asp.net jquery-datatables autofill