Reputation: 2785
Here's the response:
{"Message":"Authentication failed.","StackTrace":null,"ExceptionType":"System.InvalidOperationException"}
how can i display an alert box with the value of "Message"
.
This has not worked for me:
error: function (data) { alert(data[0]); }
or
error: function (data) { alert(data.Message); }
Upvotes: 0
Views: 368
Reputation: 7591
try
error: function(header, status, exception) {
alert(exception.Message);
}
taken from http://api.jquery.com/jQuery.ajax/#jQuery-ajax-settings
Upvotes: 2
Reputation: 2955
Either you can go with as Christian suggests or use
function (response) {
var error = $.parseJSON(response.responseText);
alert('Sorry, an error occurred. Please contact support. The error was: ' + error.Message);
}
});
Upvotes: 0
Reputation: 410
if you has got the data as string,you can use:
var msg = jQuery.parseJSON(data); alert(msg.Message);
Upvotes: 1