Why am I getting undefined in the console?
Javascript code:
var url = "/SitePages/AlertsHandler.aspx/GetAlert";
$.ajax({
type: "POST",
url: url,
data: '{alertId: \"' + alertId + '\"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
console.log(data.IncidentDesc);
}
});
C# code:
[WebMethod]
public static string GetAlert(string alertId)
{
return MyJsonObject; // on debug --> {"IncidentDesc":"assdafsdaf","IncidentRecommend":"asdfsdaf"}
}
I found the problem:
var data2 = JSON.parse(data.d);
console.log('IncidentDesc:' + data2.IncidentDesc);