Jquery datatable bind from parameterized webservice -
everything fine json result not biding result datatable please help
json rsult:[{"ourbranchid":"8001","accountid":"90186772","productid":"ca-pkr"}]{"d":null}
<script type="text/javascript"> $(document).ready(function () { $.ajax({ type: 'post', url: 'accountservice.asmx/getaccountparam', data: "{ 'account': '90186772'}", contenttype: 'application/json; charset=utf-8', datatype: 'json', success: function (data) { var datatableinstance = $('#datatb').datatable({ data: data, // data: data.d, columns: [ { 'data': 'ourbranchid' }, { 'data': 'accountid' }, { 'data': 'productid' }, ] }); $('#datatb tfoot th').each(function () { var title = $('#datatb thead th').eq($(this).index()).text(); $(this).html('<input type="text" placeholder="search ' + title + '"/>'); }); datatableinstance.api().columns().every(function () { var datatablecolumn = this; $(this.footer()).find('input').on('keyup change', function () { datatablecolumn.search(this.value).draw(); }); }); } }); }); </script>
<%@ page title="" language="c#" masterpagefile="~/site.master" autoeventwireup="true" codefile="copyjqueryajaxcallwithparameter.aspx.cs" inherits="copyjqueryajaxcallwithparameter" %> <asp:content id="content1" contentplaceholderid="headcontent" runat="server"> </asp:content> <asp:content id="content2" contentplaceholderid="maincontent" runat="server"> <script type="text/javascript"> $(document).ready(function () { $.ajax({ type: 'post', url: 'accountservice.asmx/getaccountparam', data: "{ 'account': '90186772'}", contenttype: 'application/json; charset=utf-8', datatype: 'json', success: function (data) { var datatableinstance = $('#datatb').datatable({ data: data, // data: data.d, columns: [ { 'data': 'ourbranchid' }, { 'data': 'accountid' }, { 'data': 'productid' }, ] }); $('#datatb tfoot th').each(function () { var title = $('#datatb thead th').eq($(this).index()).text(); $(this).html('<input type="text" placeholder="search ' + title + '"/>'); }); datatableinstance.api().columns().every(function () { var datatablecolumn = this; $(this.footer()).find('input').on('keyup change', function () { datatablecolumn.search(this.value).draw(); }); }); } }); }); </script> <table id="datatb" class="display" cellspacing="0" width="100%" > <thead> <tr> <th>ourbranchid</th> <th>accountid</th> <th>productid</th> </tr> </thead> <tfoot> <tr> <th>ourbranchid</th> <th>accountid</th> <th>productid</th> </tr> </tfoot> </table> </asp:content>
webservice method:
[webmethod] public void getaccountparam(string account) { datatable dtrsl; list lstacc = new list(); dtrsl = cls.accountdetailparam(account);
foreach (datarow row in dtrsl.rows) { account = new account(); a.ourbranchid = row[0].tostring(); a.accountid = row[1].tostring(); a.productid = row[2].tostring(); lstacc.add(a); } javascriptserializer js = new javascriptserializer(); js.maxjsonlength = int32.maxvalue; // context.response.write(lstacc); context.response.write(js.serialize(lstacc)); }
Comments
Post a Comment