I've gotta problem with filling javaScript array using an Ajax request. here is my code. Ajax part is working properly.
function GetColumns()
{
var x = [];
$.ajax({
url: '@Url.Content("~/AreaModel/GetColumns")',
data: {
'id': 10,
},
dataType: "json",
type: 'POST',
success: function (data) {
debugger;
var item = data.list;
for (var i = 0; i < data.count; i++) {
var val = item[i];
x.push({ field: "row.Col1.comNm", title: " " });
}
},
error: function () {
alert("error!");
}
});
var n = $("#secret").val(x);
for (var i = 0; i < 10; i++) {
//x.push({field: "row.Col1.comNm", title: " " });
}
return (x);
}
I have debugged the function with fire bug. here is the screen shot.
After the end of the ajax function, x[] become null. I have no idea what's happens to the data. Please help me..