Поскольку я использую dataTable для обработки моих данных, поступающих из базы данных, я где-то застреваю при ошибке AJAX.Как использовать dataTable в Laravel 5.1
Вот мой код на взгляд,
<table id="prodTable" class="ui red very basic collapsing celled table tableProd" cellspacing="0" width="113%">
<thead>
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
@if(isset($wholesalerConfig) && !empty($wholesalerConfig))
<?php $products = DB::connection($wholesalerdb)->table('product')->get(); ?>
@foreach($products as $product)
<tr class="griDdProd sep" id="productData">
<td class="colProd">
<div class="field">
<img class="imglist" src="data:image;base64,'..'"">
<h2>{{$product->Name}}</h2>
</div>
<p> </p>
<div class="field">
{{$product->Description}}
</div>
<p> </p>
<div class="field">
<h3>{{$product->Price}}</h3>
</div>
<p> </p>
<div class="field">
<i class="large add to cart icon">
<img src="{{URL::asset('images/add.png')}}" height="23px" width="80px" >
</i>
</div>
</td>
<td>
{{$product->Category}}
{{$product->Subcategory}}
{{$product->Field1}}
{{$product->Field2}}
{{$product->Field3}}
</td>
</tr>
@endforeach
@endif
</tbody>
</table>
В приведенной выше таблице читает все мои данные и отображает их здесь ... в то время как на стороне Js ..Я получил этот
$(document).ready(function() {
$('#prodTable').DataTable({
"processing": true,
"serverSide": true,
"pagingType": "full_numbers",
"columnDefs": [
{
"targets": [ 1 ],
"visible": false,
},
],
"ajax": {
"url": "postDatatable",
"type": "POST",
"headers": {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
},
"columns": [
{ "data": "Name" },
{ "data": "Description" },
]
});
});
И кроме того, на моей стороне контроллера,
public function searchData()
{
// $whosalerDb = Session::get('wholesalerDb');
// if(isset($whosalerDb) && !empty($whosalerDb))
// {
// DB table to use
$table = DB::table('wholesaler1');
// Table's primary key
$primaryKey = 'ID';
// Array of database columns which should be read and sent back to DataTables.
// The `db` parameter represents the column name in the database, while the `dt`
// parameter represents the DataTables column identifier. In this case object
// parameter names
$columns = array(
array('db' => 'Name', 'dt' => 'Name'),
array('db' => 'Description', 'dt' => 'Description'),
);
// SQL server connection information
$sql_details = array(
'user' => 'root',
'pass' => '',
'db' => 'wholesaler1',
'host' => 'localhost'
);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* If you just want to use the basic configuration for DataTables with PHP
* server-side, there is no need to edit below this line.
*/
include(app_path().'\classes\ssp.class.php');
echo json_encode(
SSP::simple($_POST, $sql_details, $table, $primaryKey, $columns)
);
}
}
его показывает мне ошибку, как 1) Метод исключения ERRO г на сервере side..And также на вид сбоку, Ajax ошибка
мой маршрут
Route::post('postDatatable','[email protected]');