0
即時通訊使用asp.net mvc,想從服務器端加載json數據。我有這樣的服務器端代碼:jQuery Datatables從服務器加載數據
Function GetData() As ActionResult
Dim TransactionSearchRow1 = New TransactionSearchRow With {
.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
它只是從一個TransactionSearchRow對象發回我json字符串。
我有一個客戶端代碼:
$("#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' }
]
});
}
});
});
而且簡單的HTML表:
<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響應 –
添加它後。 –
您確認成功函數中的'data'返回正確嗎? –