103
rated 0 times
[
109]
[
6]
/ answers: 1 / hits: 28126
/ 10 Years ago, mon, may 19, 2014, 12:00:00
I'm trying to loop the returning Array from PHP
. But jQuery .length
is giving me:
'undefined'
PHP:
$items = array();
$items[country] = North Korea,
$items[fruits] = array(
apple=>1.0,
banana=>1.2,
cranberry=>2.0,
);
echo json_encode( $fruits );
jQuery:
$.ajax({
url: items.php,
async: false,
type: POST,
dataType: JSON,
data: { command : getItems }
}).success(function( response ) {
alert( response.fruits.apple );
alert( response.length );
});
- Here the First Alert() is ok, by returning:
1.0
. - Then the Second Alert() to detect length
response.length
is returning:
undefined
Then how can i loop this Array (or) how to loop the Fruits (defined by PHP like $items[fruits]
) from jQuery end please?
More From » php