Why I am getting type error undefined from my jquery from my php json?
- by Brained Washed
I don't know what is wrong is am I just missing something, all my expected data is successfully receive based on firebug' console tab the problem is displaying the data.
Here's my jquery code:
success: function(data){
var toAppend = '';
if(typeof data === "object"){
for(var i=0;i<data.length;i++){
toAppend += '<tr><td colspan="2">'+data[i]['main-asin'][0]+'</td></tr>';
toAppend += '<tr><td>'+data[i]['sub-asin'][0]+'</td><td></td></tr>';
}
$('.data-results').append(toAppend);
}
}
Here's my php code:
foreach($xml->Items->Item as $item){
$items_from_amazon[] = array('main-asin'=>$item->ASIN);
foreach($xml->Items->Item->Variations->Item as $item){
$items_from_amazon[] = array('sub-asin'=>$item->ASIN);
}
}
echo json_encode($items_from_amazon); //return amazon products
And here's the result from my firebug: