jquery - loop through json string via java script -
i have retrieved data database , parsed 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 loop through array this
$(document).ready(function(){ //alert(categories); cats = jquery.parsejson(categories); (x in cats) { alert(cats.name); } }
but i'm getting nothing. problem?
try this.
$(document).ready(function(){ (x in categories) { alert(categories[x].name); } }
Comments
Post a Comment