无法使用ASP.NET MVC Ajax JQuery失败

无法使用ASP.NET MVC Ajax JQuery失败,jquery,ajax,asp.net-mvc,Jquery,Ajax,Asp.net Mvc,下面是我的ajax调用,它工作得很好,但总是成功的 $.ajax({ type: "POST", url: '@(Request.RawUrl + "/postcomment")', dataType: "json", data: data, contentType: "application/json; charset=utf-8", success: function() { alert('success'); },

下面是我的ajax调用,它工作得很好,但总是成功的

  $.ajax({
    type: "POST",
    url: '@(Request.RawUrl + "/postcomment")',
    dataType: "json",
    data: data,
    contentType: "application/json; charset=utf-8",
    success: function() {
      alert('success');
    },
    failure: function(response) {
      alert(response.d);
    }
  });
如何激活故障功能。在控制器类中,我正在做

return new HttpStatusCodeResult(500, "Error message");

但是在故障消息框中没有显示,我需要做什么才能使故障工作并显示消息。

使用状态代码回调。你从哪里得到的失败回调?只有
错误
回调

$.ajax({
  statusCode: {
    500: function() {
      alert( "error" );
    }
  }
});

使用状态代码回调。你从哪里得到的失败回调?只有
错误
回调

$.ajax({
  statusCode: {
    500: function() {
      alert( "error" );
    }
  }
});

请将
故障
替换为
错误

error: function(response) {
  alert(response.d);
}

请将
故障
替换为
错误

error: function(response) {
  alert(response.d);
}

它是
error
not
failure
。它是
error
not
failure
。记不起我为什么使用failure,一定是在internet上的某个地方看到过它,然后复制了它。记不起我为什么使用failure,我一定是在互联网上的某个地方看到了它,然后复制了它。我在某个地方看到了失败,并开始使用它。我已经用我应该使用的正确属性更新了答案。statusText是正确的属性。接受编辑,我会标记答案。我在某个地方见过失败,并开始使用它。我已经用我应该使用的正确属性更新了答案。statusText是正确的属性。接受编辑,我将标记答案。