gpt4 book ai didi

jquery - getResponseHeader 在 IE 8 中返回 null

转载 作者:行者123 更新时间:2023-11-30 23:46:38 25 4
gpt4 key购买 nike

对于 Spring MVC Controller 中的验证错误,我将自定义 header error 设置为响应 header 。我可以在 Firefox 3.5 中访问该响应 header 。但在 IE 8 中不行。请告诉我向 Jquery 客户端显示自定义错误消息的正确方法。

    var jqxhr=$.post("saveAcc.htm",{ data: data});

jqxhr.success(function() {
alert("Saved");
});

jqxhr.error(function(thrownError){
fnSetError(jqxhr.getResponseHeader('error'));
alert(jqxhr.getAllResponseHeaders()); //returns empty
//alert('responseText '+ thrownError.responseText);
alert(jqxhr.getResponseHeader('error')); //return null
oTable.fnReloadAjax();
});

最佳答案

如果要调用JS错误处理函数,请在服务器上抛出异常。

或者,您可以将 HTTPStatus 设置为 500 或其他错误状态

response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
//response.setStatus(500);

但我认为你的做法是错误的。验证错误不是应用程序错误,您应该在成功消息中处理这些错误。

jqxhr.success(function(data) { 
if(data['validationMessages'].length > 0 ) {
//deal with the validation issues
}
});

这可能有帮助:http://outbottle.com/spring-3-web-mvc-exception-handling-incorporating-ajax/

关于jquery - getResponseHeader 在 IE 8 中返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8666208/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com