为datatable插件中的每个页面索引更改分隔ajax调用

时间:2012-06-06 09:07:30

标签: jquery ajax callback datatables webmethod

我正在寻找这个问题的解决方案超过一个星期,我找不到。这是我的问题

我们都知道通过Jquery中的datatables插件访问ajax数据分页的基本方法。在此示例中,检索所需的所有数据,并在浏览器内存中完成分页。我不需要这样。由于数据量巨大,我面临性能问题,因此我们需要更复杂的方法。这是每个页面索引更改的单独ajax调用。

我已经阅读了this link这是用于PHP的,所以对我没用。

我读了基于MVC的this link,所以再次对我无效。

这是我的代码,所以我可以这样做来修改我的代码

在A.aspx页面上

function showData(P1,P2) {
$.ajax({
    type: 'POST',
    url: 'A.aspx/GetDataList',
    data: "{'P1':'" + P1+ "','P2':'" + P2+ "'}",
    contentType: 'application/json; charset=utf-8',
    dataType: 'json',
    success: function (msg) {
   //make string of data here
   $('#example').html(table).dataTable();
   }

现在A.aspx.cs

[System.Web.Services.WebMethod()]
[System.Web.Script.Services.ScriptMethod()]
public static List<myclass> GetDataList(string P1, string P2)
{
    //make object of city class
    myclass cl = new myclass();
    cl.what = P1;
    cl.where = P2;
    return cl.GetDataList1();

}

这是我的班级功能

public List<mycls> GetDataList1()
{

    try
    {

        Database db = DatabaseFactory.CreateDatabase();
        DbCommand oCmd = db.GetStoredProcCommand("sp");
         db.AddInParameter(oCmd, "@a", DbType.String, this.what);
         db.AddInParameter(oCmd, "@b", DbType.String, this.where);
        DataSet dsResult = db.ExecuteDataSet(oCmd);

            var query = from o in dsResult.Tables[0].AsEnumerable()

                        select new mycls
                        {
                            ID = o.Field<int>("ID"),
                            Name= o.Field<string>("Name")

                        };
            List<mycls> lstDisplay = new List<mycls>();
            lstDisplay.AddRange(query);
            return lstDisplay;


    }
    catch (Exception ex)
    {

    }
 }

0 个答案:

没有答案