I have city object in my project. I want to create a jquery array with some city objects. I can take city list from .ashx file and create single city objects. But I couldn't push them to an array. Here is my code:
var postDataCity = { funcName: "GetCities" };
var cities = [];
var city = {};
$.ajax({
type: "POST",
contentType: "application/x-www-form-urlencoded; charset=utf-8",
dataType: "json",
url: "KurumInformation.ashx",
data: postDataCity,
async: true,
success: function (msg) {
$.each(msg, function (i, v) {
city.M_CityId = this.M_CityId ;
city.M_CityName= this.M_CityName;
cities.push(city);
});
},
error: function (d) {
alert('error :' + d);
},
});
console.log(cities);
After this I check cities but there is an error I think because I can't see cities in console. Where is my mistake?