正如您在下面看到的那样,我尝试了代表的console.log,它在控制台中为我生成了一个结果对象。该对象中包含公司,服务,contact_name和其他属性。但是,它总是说“ TypeError:代表是空的,无法访问它的属性” company”。
如何将“ typeof”并入此处,如此处所述:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/cant_access_property ....那将是解决方案吗?
jQuery.post(ajaxurl, data, function(response){
if(response.length > 0){
var html = '<ul>';
jQuery.each(response,function( arrayID, representant ){
html+= '<li><h3>'+representant.company +'</h3>';
console.log(representant);
html+='<p><b>Serving: </b>' + representant.serving + '<br />';
html+='<b>Contact: </b>' + representant.contact_name + '<br/ ></p>';
html+='<p><b>Address:</b> <br />' + representant.address + '<br />';
html+= representant.city;
html+= ', ';
html+= representant.state_code;
html+=' ';
html+= representant.zip_code;
html+='</p><p><b>Phone: </b>';
html+= representant.phone;
html+= '<br /> <b>Email: </b> ';
html+= representant.email;
html+='</p></li>';
});
html+= '</ul>';
} else {
html = 'We are sorry, we didn\'t found any Sales Representative on this area.';
}
display_results(html);
});
}