Why I am getting type error undefined from my jquery from my php json?

Posted by Brained Washed on Stack Overflow See other posts from Stack Overflow or by Brained Washed
Published on 2012-10-01T09:23:16Z Indexed on 2012/10/01 9:37 UTC
Read the original article Hit count: 264

Filed under:
|
|
|

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: enter image description here

© Stack Overflow or respective owner

Related posts about php

Related posts about jQuery