我正在使用服务器端为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