Maybe somewhere in your project there's already a lower level catch for ajax errors, like an ajaxSetup or an ajaxError.
Also, is jQuery the only framework implemented?
题
Hello how to prevent browser from alerting by itself, when returning a HttpStatusCodeResult
object.
The Action Method:
[HttpPost]
public ActionResult Finish()
{
//Throw the status code result
return new HttpStatusCodeResult(500,"Oops something wrong happened!");
}
The script
jQuery.ajax({
url: '@Url.Action("Finish","Home")',
type: "POST",
success : function(result) {
alert("success is:"+result);
},
error: function (response, status, errorThrown) {
alert(errorThrown);
}
});
The result of calling Finish() Action is displayed in the alert();
function, but
under the custom alert,
The browser also alerts with a message - "The page cannot be displayed because an internal server error has occurred."
The actual problem was, as #tanathos pointed out, a global function:
jQuery(document).ajaxError(function (e, jqxhr, settings, exception) {
if (jqxhr != null) {
alert(jqxhr.responseText);
}
Thank you very much for your help. Question Closed.
解决方案
Maybe somewhere in your project there's already a lower level catch for ajax errors, like an ajaxSetup or an ajaxError.
Also, is jQuery the only framework implemented?