2011-12-29 87 views
5

对于Spring MVC控制器中的验证错误,我将自定义标头错误设置为响应标题。我可以在Firefox 3.5中访问该响应头。但不是在IE 8中。 请告诉我,将自定义错误消息显示给Jquery客户端的正确方法。getResponseHeader在IE 8中返回null

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(); 
    }); 
+0

我不知道这是否会有所帮助,但试试这个:http://forum.jquery.com/topic/jquery-ajax-ie8-problem,这一个关于IE8中jquery $ .ajax的bug报告,以及一些可能的修复。 – joao 2013-09-13 13:58:52

回答

0

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