javascript - jQuery Datatables load data from server -


im using asp.net mvc, want load json data server side. have piece of server side code:

function getdata() actionresult              dim transactionsearchrow1 = new transactionsearchrow {             .status = status.cancelled,             .transactinid = 12345,             .creditcardnumber = "1234324324",             .supplier = "office depot",             .createdat = new datetime(2008, 12, 28),             .amount = 500             }              dim transactionsearchrowjson = jsonconvert.serializeobject(transactionsearchrow1)              return json(transactionsearchrowjson)          end function 

its send me json string transactionsearchrow object.

i have client-side code:

$("#searchbtn").on("click", function () {                 $.ajax({                     url: '/transaction/getdata',                     method: 'post',                     datatype: 'json',                     success: function (data) {                         $('#transactiontable').datatable({                             data: data,                             columns: [                                 { 'data': 'status' },                                 { 'data': 'transactinid' },                                 { 'data': 'creditcardnumber' },                                 { 'data': 'supplier' },                                 { 'data': 'createdat' },                                 { 'data': 'amount' }                             ]                          });                      }                 });             }); 

and simple html table:

<table id="transactiontable" class="table table-striped table-bordered table-list">                     <thead>                         <tr>                             <th class="col-md-1">status</th>                             <th>transid</th>                             <th>ccn</th>                             <th>supplier</th>                             <th>created date</th>                             <th>amount</th>                         </tr>                     </thead>                      <tbody>                      </tbody>                 </table> 

json response: enter image description here

but error when im click "search" button. enter image description here

enter image description here

i think response data format not right. please refrence example.the ajax response should object has array property named "data". i'm not familiar vb,so give c# code snippet. change server side action code following:

 return json(new {         data: new list<transactionsearchrow>(){transactionsearchrow1}     }) 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -