c# - jQuery Datatables webforms call -


i trying use datatables within webforms application. unfortunatly whole html page instead of json data :'( code.

<script type="text/javascript">     $(document).ready(function () {         $('#grid').datatable({             "datatype": 'json',             "bserverside": true,             "sajaxsource": 'gategoriesmanagement.aspx/getpersonlist',             "bprocessing": true,             "aocolumns": [                              { "sname": "d.name" },             ]          });     });  </script> 

my webmethod

  [webmethod]     [scriptmethod(responseformat = responseformat.json)]     public static string getpersonlist()     {         list<personne> personelist = new list<personne>();          personne person = new personne();         person.name = "test1";         personelist.add(person);          person = new personne();         person.name = "test2";          person = new personne();         person.name = "test3";          personelist.add(person);         formatedlist list = new formatedlist();          list.itotaldisplayrecords = 10;         list.itotalrecords = 200;         list.aadata = personelist;          var javascriptserializer = new javascriptserializer();         string jsonstring = javascriptserializer.serialize(list);         return jsonstring;     } 

and alert in browser

 datatables warning: table id={id} - ajax error  

it appear webmethod not accessible should ???

the magic piece of code makes work of 1.10.12 ajax parameter. asp.net wraps json results in .d property, need execute callback on object.

    $('#tableid').datatable(     {         "processing": true,         "serverside": true,         "statesave": false,         "lengthmenu": [[10, 30, 100, -1], [10, 30, 100, "all"]],  // 1st = page length values, 2nd = displayed options         ajax: function (data, callback, settings) {             $.ajax({                 url: "/userservice.asmx/getusers",                 type: 'post',                 contenttype: 'application/json',                 datatype: "json",                 data: json.stringify(data),                 success: function (data) {                     $spinner.hide();                     callback(data.d); // execute callback function on wrapped data                 }             });         }, 

Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -