我正在使用服務器端爲jQuery數據表進行大量處理,因爲數據可能超過10,000,但我收到錯誤。爲什麼我的webservice回覆ok狀態,但沒有填充數據表?
我使用純的jQuery用c#.ASMX web服務
數據表警告:表ID =例如 - 請求未知參數 '用戶名' 爲0的行,列0
我檢查返回狀態,它是好的200,也是JSON數據返回,我檢查了響應部分,但仍然是上述錯誤。
代碼:
function show()
{
$('#example').DataTable
(
{
//data: data,
columns:
[
{'data': 'UserName'},
{'data': 'Password'},
],
bServerSide: true,
sAjaxSource: 'http://localhost:8373/himher.asmx/getUsers',
sServerMethod: 'post'
});
}
<div class="container-fluid">
<table id="example" class="display" width="100%"></table>
</div>
我剛纔把以上相關的代碼。
C#的WebMethod:
[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true)]
public void getUsers(int iDisplayLength, int iDisplayStart, int iSortCol_0, string sSortDir_0, string sSearch)
{
try
{
basicoperation bop = new basicoperation();
DataTable dt;
dt = bop.getUsers(iDisplayLength, iDisplayStart, iSortCol_0, sSortDir_0, sSearch); // fetching users
dt.TableName = "usersDT"; // a datatable must be named before serialization
DataRow dr = dt.Rows[0];
string jsonDataTable = JsonConvert.SerializeObject(dt); //a data table must be serialized before transmitting
var retObj = new
{
iTotalRecords = dr["TotalCount"].ToString(),
iTotalDisplayRecords= dt.Rows.Count,
aaData = jsonDataTable
};
JavaScriptSerializer js = new JavaScriptSerializer();
Context.Response.Write(js.Serialize(retObj)); // converting a .net object to JSON
}
catch (Exception ex)
{
throw ex;
}
}
回報:
{"iTotalRecords":"19","iTotalDisplayRecords":5,"aaData":"[{\"RowNum\":2,\"TotalCount\":19,\"Id\":39,\"UserName\":\"adsbkj\",\"Password\":\"23123\"},{\"RowNum\":3,\"TotalCount\":19,\"Id\":40,\"UserName\":\"adsbkj\",\"Password\":\"23123\"},{\"RowNum\":4,\"TotalCount\":19,\"Id\":37,\"UserName\":\"asd\",\"Password\":\"23\"},{\"RowNum\":5,\"TotalCount\":19,\"Id\":2,\"UserName\":\"asd\",\"Password\":\"asdasd\"},{\"RowNum\":6,\"TotalCount\":19,\"Id\":5,\"UserName\":\"asd\",\"Password\":\"asda\"}]"}
'DataTables warning:table id = example - 請求未知參數'UserName'爲第0行,第0列。哪一行顯示?請將我們指向具體的行。如果有例外情況,請附上例外情況的截圖。 – mjwills