为什么我收到请求的未知参数错误?

时间:2017-08-09 10:37:43

标签: javascript c# jquery ajax datatables

我正在为Jquery数据表填充和使用服务器端代码。我正在使用服务器端处理,因为数据可能超过10,000但我收到错误。

DataTables警告:table id = example - 请求的未知参数' UserName'对于第0行,第0列。

代码:

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;
    }    

}

返回:

{&#34; iTotalRecords&#34;:&#34; 19&#34;&#34; iTotalDisplayRecords&#34;:5,&#34; aaData&#34;:&#34; [ {\&#34; ROWNUM \&#34;:2,\&#34; TOTALCOUNT \&#34;:19,\&#34;标识\&#34;:39,\&#34;用户名\ &#34;:\&#34; adsbkj \&#34; \&#34;密码\&#34;:\&#34; 23123 \&#34;},{\&#34; ROWNUM \ &#34;:3,\&#34; TOTALCOUNT \&#34;:19,\&#34;标识\&#34;:40,\&#34;用户名\&#34;:\&# 34; adsbkj \&#34; \&#34;密码\&#34;:\&#34; 23123 \&#34;},{\&#34; ROWNUM \&#34;:4,\ &#34; TOTALCOUNT \&#34;:19,\&#34;标识\&#34;:37,\&#34;用户名\&#34;:\&#34; ASD \&#34; ,\&#34;密码\&#34;:\&#34; 23 \&#34;},{\&#34; ROWNUM \&#34;:5,\&#34; TOTALCOUNT \&# 34;:19,\&#34;标识\&#34;:2,\&#34;用户名\&#34;:\&#34; ASD \&#34; \&#34;密码\ &#34;:\&#34; asdasd \&#34;},{\&#34; ROWNUM \&#34;:6,\&#34; TOTALCOUNT \&#34;:19,\&# 34;标识\&#34;:5,\&#34;用户名\&#34;:\&#34; ASD \&#34; \&#34;密码\&#34;:\&# 34; ASDA \&#34;}]&#34;}

0 个答案:

没有答案