I'm calling a method that is in the code-behind. Once I got the data, I'm not able to copy the data to a local variable.
I've created a local variable. I've tried to console.log the result of the Ajax call in 2 places. First, inside the success callback method, and secondly outside.
Inside the success method, I get something like [object, object, object ]. However, outside, I'm getting just an empty array [].
var rowArray=[];
$.ajax({
type: "POST",
url: "Default.aspx/GetData",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: '{ dataId: 1 }',
success: function (response) {
rowArray = JSON.parse(response.d);
//console.log(rowArray); --> this logs [object, object, object ]
},
failure: function (response) {
alert(response.d);
}
});
//console.log(rowArray); --> this logs []
Any reason why I'm not able to copy the response to a local variable?
Thanks for helping