I have retrieved data from database and parsed it like this javascript
var categories = <?php echo json_encode($categories); ?>;
in source code categories variable has following values:
var categories = [{"id":"27","name":"john"},{"id":"8","name":"jack"}]
now I'm trying to loop through this array like this
$(document).ready(function(){
//alert(categories);
cats = jQuery.parseJSON(categories);
for (x in cats)
{
alert(cats.name);
}
}
but I'm getting nothing. Where is the problem?