Php 如何在使用ajax时在数据表中显示img
我在Laravel5.5中工作,我实现了datatables,我在ajax中使用它,我工作得很好,但是现在我需要在datatables中显示和img,但我不知道怎么做。我读了渲染文档,但还是弄丢了。 表代码:Php 如何在使用ajax时在数据表中显示img,php,ajax,datatable,Php,Ajax,Datatable,我在Laravel5.5中工作,我实现了datatables,我在ajax中使用它,我工作得很好,但是现在我需要在datatables中显示和img,但我不知道怎么做。我读了渲染文档,但还是弄丢了。 表代码: <div class="row-fluid margin-body"> <table id="productos" class="table table-hover table-condensed" >
<div class="row-fluid margin-body">
<table id="productos" class="table table-hover table-condensed" >
<thead>
<tr>
<th >Id</th>
<th>Producto</th>
<th>Cantidad </th>
<th>img</th>
<th></th>
</tr>
</thead>
</table>
</div>
我在写问题时发现了错误。此代码应该适用于您。如果您发现错误,并且问题仍然有价值,您应该在此处的“答案”部分发布解决方案的解释。如果问题不再有价值,你应该删除它。
$(document).ready(function(){
listar();
});
var listar = function (){
var table = $('#productos').DataTable({
"processing": true,
"serverSide": true,
"ajax": "ajaxProducto",
"columns":[
{data:'id'},
{data:'nombre'},
{data:'stock'},
{data: 'imagen',
"render": function(data, type, row) {
return '<img src="'+data+'" />';
}},
{defaultContent:
"<a type='button' class='editar btn btn-xs btn-mini btn-primary' data-toggle='modal' data-target='#myModalEditar'>Editar</a><a type='button' class='eliminar btn btn-xs btn-mini btn-danger' >Eliminar</a><a type='button' class='btn btn-xs btn-mini btn-success detalles' data-toggle='modal' data-target='#myModalDetalles'>Detalles</a>"
}
],
"language": idioma_esp
});
}
{data: 'imagen',
"render": function(data, type, row) {
return '<img src="img/productos/'+data+'" height="42" width="42"/>'; }}
Route::get('/ajaxProducto', function() {
return datatables()->collection(App\Producto::all())->toJson();
});