views:

256

answers:

1

Hello

I have this php code

   $ids = array(1,2,3);
   $names = array("cat","elephant","cow"); 
   $originalSettings = array ('ids'=>$ids,'names'=>$names);
   $jsonSettings = json_encode($originalSettings);
   echo $jsonSettings;

and this is the jQuery code

$.post("ajax.php", {},
function(data){
data.ids.each(function(i) {
alert(data.names[i]);
}
//is it possible to receive the arrays and navigate them   
}, "json");

How can I pass arrays using json and receive them in javascript?

Thanks

+1  A: 

Try:

function(data) {
    $.each(data.array1, i) {
        alert(data.array2[i]);
    }
}
kim3er
Thanks It works, it is slightly different $.each(data.array1,function(i){alert(data.array2[i]);});
ahmed
That's it, I knew I was missing a function. Glad it worked.
kim3er