I have this code :
var mapcity = new Array([]);
$.ajax({
type: 'GET',
url: '/home/DrawMap',
dataType: 'json',
success: function (data) {
var len = data.length;
for (var i = 0; i < len; i++) {
// mapcity['' + data[i].name + ''] = { center: new google.maps.LatLng(data[i].x, data[i].y), population: data[i].population, name: '' + data[i].name + '' };
mapcity['' + data[i].name + ''] = { center: new google.maps.LatLng(data[i].x, data[i].y), population: data[i].population, name: ''+data[i].name+'' };
//newarr[i] = data[i].name;
alert(mapcity[0].population)
}
}
});
}
This is a part of my code, and this is the function from controller :
public ActionResult DrawMap() {
string data = "[{ 'x':31.949454,'y': 35.932913,'population':50000,'name':'amman'},{ 'x':33.79,'y': 33.39,'population':100000,'name':'Zarqa'}]";
data=data.Replace("'","\"");
return this.Content(data, "application/json");
}
When I run this, its het the JSON data from the controller but without saving it into the mapcity variable! And it does nothing. how can I solve it and what iam doing wrong?