2017-07-30 179 views
-1

想要從asp.net mvp服務器端加載數據。 有jQuery的Ajax的功能:jQuery Datatables加載數據ajax

Function GetData() As ActionResult 

      Dim TransactionSearchRow1 = New TransactionSearchRow With { 
      .status = Status.Cancelled, 
      .transactionId = "12345", 
      .creditCardNumber = "1234324324", 
      .supplier = "Office Depot", 
      .createdAt = New DateTime(2008, 12, 28), 
      .amount = 500 
      } 


      Dim anon = New With {.data = New List(Of TransactionSearchRow) From {TransactionSearchRow1}} 
      Dim jsonData As String = JsonConvert.SerializeObject(anon, Formatting.Indented) 

      Return Json(jsonData) 

     End Function 

但沒有什麼是發生時,即時通訊點擊BTN:即返回我1行數據的

$("#SearchBtn").on("click", function() { 

       $.ajax({ 
        url: '/Transaction/GetData', 
        success: function (dataReturend) { 
         $("#TransactionTable").DataTable({ 
          ajax: '/Transaction/GetData', 
          data: dataReturend, 
          columns: [ 
          { data: 'status' }, 
          { data: 'transactionId' }, 
          { data: 'creditCardNumber' }, 
          { data: 'supplier' }, 
          { data: 'createdAt' }, 
          { data: 'amount' } 
          ] 
         }); 
        } 
       }); 
      }); 

和服務器端。 enter image description here

服務器端返回的數據是這樣的: enter image description here

JSON格式:寫在你的單擊事件大火不需要的2倍

{ 
"data": [ 
{ 
"status": 2, 
"transactionId": 12345, 
"creditCardNumber": "1234324324", 
"supplier": "Office Depot", 
"createdAt": "2008-12-28T00:00:00", 
"amount": 500.0 
    } 
    ] 
} 
+0

你能告訴你的迴應JSON的樣子 – Ashish451

+0

是SRY加入現在 –

+1

能否請您提供它以JSON格式互不發佈圖片? –

回答

1

代碼。 代碼應該是這樣的

$("#SearchBtn").on("click", function() { 

    $("#TransactionTable").DataTable({ 
     ajax: '/Transaction/GetData', 
     columns: [ 
     { data: 'status' }, 
     { data: 'transactionId' }, 
     { data: 'creditCardNumber' }, 
     { data: 'supplier' }, 
     { data: 'createdAt' }, 
     { data: 'amount' } 
     ] 
    }); 
}); 

更多參考Datatable

+0

如果有效,你可以接受這個答案 – Ashish451

+0

現在工作:( –

相關問題