通过jquery从服务器发出警报响应
本文关键字:响应 jquery 服务器 通过 | 更新日期: 2023-09-27 18:20:49
以下是响应:
{"Message":"Authentication failed.","StackTrace":null,"ExceptionType":"System.InvalidOperationException"}
如何显示值为"Message"
的警告框。这对我不起作用:
error: function (data) { alert(data[0]); }
或
error: function (data) { alert(data.Message); }
尝试
error: function(header, status, exception) {
alert(exception.Message);
}
取自http://api.jquery.com/jQuery.ajax/#jQuery-ajax设置
如果数据是字符串,可以使用:
var msg = jQuery.parseJSON(data); alert(msg.Message);
您可以按照Christian的建议使用,也可以使用
function (response) {
var error = $.parseJSON(response.responseText);
alert('Sorry, an error occurred. Please contact support. The error was: ' + error.Message);
}
});