您好我有一个ajax请求来检索产品列表。请求不太知道我的表生成与颜色表连接 table产品[id,name,imgs,color_id] 表格颜色[id,name,code]
如何通过ajax获取颜色代码:
以下是我的代码的一部分:
$('#product1').on('change', function(e) {
var product_id = e.target.value;
// Ajax Products Color
if(product_id > 0) {
$.get('/2c/ajax-compare?product_id=' + product_id, function(data) {
$('#productProperty1').empty();
$.each(data, function(index, prodObj) {
if(index == 0)
{
var square = '<a class="btn compare d-block mb-3 active-item">Compare<img class="pl-2 img-fluid" src="{{ asset('/asstes/images/bleu_active.png' ) }}" alt=""></a>';
var image = '<img class="img-fluid mb-3" src="{{ asset('') }}'+prodObj.imgs+' " alt="">';
}
//var color = '<p>'+prodObj.color_id+'</p>';
//这里我想得到颜色代码&#34; prodObj.color_id&#34;
$('#productProperty1').append(square, image);
})
})
}
else {
$('#productProperty1').empty();
var square = '<a class="btn compare d-block mb-3">Compare<img class="pl-2 img-fluid" src="{{ asset('/asstes/images/white_desactive.png' ) }}" alt=""></a>';
var image = '<img class="img-fluid mb-3" src="{{ asset('/asstes/images/products/phones/default.png' ) }}" alt="">';
$('#productProperty1').append(square, image);
}
});