【问题标题】:getResponseHeader return null in IE 8getResponseHeader 在 IE 8 中返回 null
【发布时间】:2012-01-29 18:34:29
【问题描述】:

对于 Spring MVC Controller 中的验证错误,我将自定义标头 error 设置为响应标头。我可以在 Firefox 3.5 中访问该响应标头。但不是在 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(); 
     });

【问题讨论】:

标签: jquery internet-explorer httpresponse


【解决方案1】:

如果要调用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/

【讨论】:

    猜你喜欢
    • 2011-08-24
    • 1970-01-01
    • 2011-05-21
    • 2013-07-31
    • 2022-06-14
    • 1970-01-01
    • 1970-01-01
    • 2012-11-14
    • 1970-01-01
    相关资源
    最近更新 更多