problems using $.map() - or maybe it should be done another way
I'm building a function that gets a JSON array from a database to set the variable equal to that array. The variable can contain an array of several cities, but a simple example at the desired completion of the function is shown below. Firebug tells me this JSON passes, but I can't get $.map() to complete the function. It should be simple, but I don't understand $.map() to make it work in ajax. Also, maybe there is another way to do this.
So desired result is:
citiesWithBoroughs=[{"city":"New York, New York, United States"}]
The code is:
citiesWithBoroughs = function (request, response){
$.ajax({
url: "getCitiesWithBoroughs.php",
data: //it works
type: "POST",
dataType: "json",
success: function (data){
response($.map( data, function (item){
console.log(item.city);
return {city: item.city};
}));
}
});
}
citiesWithBoroughs(function(city){
$each(city, function(){
alert(item.city + "|cWB2");
});
});