0
我有一個表單來搜索數據庫中的任何人。 然後我想在DataTable中顯示搜索結果。AJAX&PHP:從表單提交GET請求的DataTable顯示搜索結果
我使用刀片模板化HTML。
這是我的形式:
<form id="myform" method="GET" action="{{ site_url('person/search') }}">
這是我的DataTable節在我的HTML
<section class="panel" style="margin-top:20px;">
@include(config_item('theme').'.person.part.table-person', compact('result'), ['id' => 'persons'])
</section>
這是我的表:
<table id="{{ $id }}" data-toggle="table" data-mobile-responsive="true">
<thead>
<tr>
<th data-field="image" data-align="center">Image</th>
<th data-field="id" data-visible="false">ID</th>
</tr>
</thead>
</table>
而且最後是我的AJAX代碼:
$(document).ready(function() {
$('#myform').submit(function() {
$.ajax({
dataType: json,
data: $(this).serialize(),
type: $(this).attr('method'),
url: $(this).attr('action'),
success: function(response) {
$('#persons').html(response);
}
});
return false;
});
});
使用所有代碼,我無法顯示搜索結果。
我做錯了什麼? 感謝
什麼是響應返回的數據? – aldrin27
'dataType:引號之間的「JSON」 –