jquery – 使用AJAX错误获取服务器响应?

对于不正确的Ajax操作,我将HTTP标头代码设置为403并发送以下响应:
{"code":"403","status":"Forbidden","message":"You cannot do this"}

但是,在处理我的错误时我无法访问此数据…是否可以从jqXHR中获取“消息”数据?

像jqXHR.message这样的东西?

非常感谢您的帮助…

EDIt:

error: function (xhr) {
            $(".alert").html(xhr.responseText);
          },

这返回:

{"code":"403","message":"You cannot do this"}

但是xhr.responseText.message不返回任何东西…

编辑:这段代码工作:

error: function (xhr) {
    var jsonResponse = JSON.parse(xhr.responseText);
    $(".alert").html(jsonResponse.message);
  },

解决方法

你应该得到jQuery’error’回调…
http://api.jquery.com/jQuery.ajax/
error: function(xhr,status,error) {
    alert(xhr.responseText);
 }

(btw .. ur代码?)

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: <span id=&quot...
jQuery 添加水印 <script src="../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...