How do you trigger the “error” callback in a jQuery AJAX call using ASP.NET MVC?

后端 未结 6 1501
心在旅途
心在旅途 2020-12-12 21:04

This is related to my question on how to handle errors from jQuery AJAX calls. Several responses suggested that I use the \"error\" callback to display any errors from a jQ

6条回答
  •  醉酒成梦
    2020-12-12 21:30

    If you're using MVC 3, then you can return an ActionResult in your controller that has the HTTP status code and status message together:

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

    Then, in your error callback:

    error: function (request, textStatus, errorThrown) {
        alert(request.statusText);
    }
    

提交回复
热议问题