JQuery: Store JSON results in a JavaScript array? -
i have php script creates json array called 'cities'.
i can retrieve info using next jquery:
$.ajax({ datatype: "json", url: "mysql.php", success: function(data){ console.log(data[0]);//returns first item in cities array };
but unsure how loop through info retrieved , come in javascript array.
i dont have anyway of initialising count, such as:
var counter = cities.length;
it doesnt seem recognised 'cities; name of retrieved json array.
am missing in ajax script?
$.ajax({ datatype: "json", url: "mysql.php", success: function(data){ $.each(data.info , function() { //refer json object address actual names var cityname = this.cityname; }); };
javascript jquery ajax arrays json
No comments:
Post a Comment