I have a PHP script which creates a JSON array called 'cities'.
I can retrieve data from that using the following JQuery:
$.ajax({
dataType: "json",
url: "mysql.php",
success: function(data){
console.log(data[0]);//Returns first item in cities array
};
But I am unsure how to loop through the data retrieved and enter it into a JavaScript array.
I dont really have anyway of initialising a count, such as:
var counter = cities.length;
it doesnt seem to recognised 'cities; is the name of the retrieved JSON array.
Am I missing something in my ajax script?
data.length
? – Floyd Pink Feb 7 at 2:35console.log(data)
? – Dom Feb 7 at 2:36