Object's field cannot be accessed after $.ajax call in success function - it is undefined
- by dragonfly
I have a $.ajax call and and server returns JSON. This is my call:
var result; // tmp variable just for playing with Chrome console
$.ajax({
type: "GET",
url: "ashxJSON.ashx",
data: { name: "some sample data" },
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
result = msg;
console.log(msg);
$("#output").append("<p>" + msg.message + "</p>");
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(textStatus);
console.log(errorThrown);
}
});
Server returns exactly this string:
{ "messsage": "Hello World to ..."}
And now, when I:
console.log(msg)
I see:
Object messsage: "Hello World to..."
proto: Object
But when I access
msg.message
or
msg["message"]
I see:
undefined
What is wrong with me / that msg object?