Здравствуйте, почему показывает ошибку в консоль?
* Uncaught TypeError: Cannot read property 'special' of undefined *
Ответ есть
{product_id: "51", thumb: "...", name: "...", description: "..", price: "3563р.", …}, но почему-то ошибка появляется
Сам запрос ajax
$('input[name="search"]').keyup(function(){
$('#ajax_search').empty();
var search=$('input[name="search"]').val();
var base=window.location.origin+window.location.pathname;
$.ajax({
url: 'search.php',
type: 'post',
data: 'search_text=' + search,
dataType: 'json',
success: function(json) {//console.log(json.products);
var products=json.products;
$('.ajax-search').css('display','block');
if(json.status){
for (i = 0; i < 5; i++) {
console.log(json.products[i]);
if(json.products[i].special){
var price=json.products[i].special;
}else{
var price=json.products[i].price;
}
var html= '<div class="row borders">';
html+='<div class="col-md-3">';
html+=' <a href="'+products[i].href+'" ><img class="img-thumbnail p_name" src="'+products[i].thumb+' " width="50px"></a>';
html+='</div>';
html+='<div class="col-md-3">';
html+=' <a href="'+products[i].href+'" ><span>'+products[i].name+'</span></a>';
html+='</div>';
html+='<div class="col-md-3">';
html+=' <a href="'+products[i].href+'" ><span>'+products[i].price+'</span></a>';
html+='</div>';
html+='<div class="col-md-3">';
html+=' <a href="javascript:;" onclick="cart.add('+products[i].product_id+', '+products[i].minimum+');" class="btn btn-primary"><i class="fa fa-shopping-cart"></i></a>';
html+='</div>';
html+='</div>';
$('#ajax_search').append(html);
//('<li class="list-group-item"> <a href="'+products[i].href+'" ><img class="img-thumbnail" src="'+products[i].thumb+' " width="50px"><span class="p_name">'+products[i].name+'</span><span class="p_name">'+products[i].price+' </span></a><a href="javascript:;" onclick="cart.add('+products[i].product_id+', '+products[i].minimum+');" class="btn btn-primary"><i class="fa fa-shopping-cart"></i></a></li>');
}
var html='<div class="col-md-12">';
html+='<a href="'+base+'?route=product/search&search='+search+'"><button type="button" class="btn btn-block btn-default btn-sm"> VIEW ALL '+products.length+' PRODUCTS</button>';
$('#ajax_search').append(html);
}else{
$('#ajax_search').append('<li class="list-group-item"><a href="#"><span>No Data Found</span></a></li>');
}
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
});