我有一个modal(bootstrap弹出窗口)包含一个表。现在,当我调用ajax并获得成功响应时,我希望得到弹出窗口的响应并将其显示在表格中,一切正确但我的图像没有显示,有什么问题?
的Ajax:
function detailOrder($id){
var url= "{{ URL::to('admin/detail_order')}}"+"/"+$id;
$.ajax({
type:"get",
url:url,
data:"",
success:function(response){
console.log(response);
$('#order').modal('show');
var trHTML = '';
$.each(response, function (i, detail_orders) {
for (i = 0; i < response.order[0].detail_orders.length; i++) {
for(j = 0;j<response.order[0].detail_orders[i].product.length;j++){
trHTML +=
'<tr><td>'
+'<img class="table_image" id="pic">'
+ '</td><td>'
+ response.order[0].detail_orders[i].product[j].product_name
+ '</td><td>'
+ response.order[0].detail_orders[i].quantity
+ '</td><td>'
+ response.order[0].detail_orders[i].product[j].price
+ '</td><td>'
+ response.order[0].detail_orders[i].total_amount
+ '</td></tr>';
$("#pic").attr("src","{{ URL::to('admin/storage')}}"+"/"+response.order[0].detail_orders[i].product[j].product_image);
}
$('#tBody').append(trHTML);
}
});
},
error:function(){
console.log("fail");
}
})
}
答案 0 :(得分:0)
试试这个
success:function(response){
var html = ''; //initialize your html
for(i=0;i<response.length;i++) //loop depends on the length of response
{
html+= //concatinate the html data in this variable
'<tr>'+
'<td>'+response[i].id+'</td>'+
'</tr>';
}
$('#tBody').html(html); //pass the html data to your body
}