2014-09-18 5 views
1

가에서 responseText 내가 기대하지만 실패() 메서드에서 항상 빈 문자열 (완료) 메소드에서 jQuery 코드jQuery를 포스트 실패() 콜백

  var posting = $.post(
       url, 
       json 
      ).fail(function(jqXHR, textStatus, errorThrown) { 
       alert("An Error Occurred: "+jqXHR.responseText); 
       } 
      ).done(function(response, textStatus, jqXHR) { 
       alert("Success: " + jqXHR.responseText); 
       } 
      ) 
      ; 

을 고려 빈에서 responseText에게 있습니다.

서블릿 코드는 그래서 같다 : 나는 jqXHR.responseText를 볼 것으로 예상하고있어 실패 할 방법은

try { 
    doSomething(); 
    response.getOutputStream().print("doSomething worked properly"); 
} 
catch (Exception e) { 
    response.sendError(500, e.getMessage()); 
    response.getOutputStream().print("doSomething failed with error: " + e.getMessage()); 
} 

서블릿 인쇄 문에서 값을 가지고 있지만, 대신에 항상 비어 있습니다.

답변

0

분명히 "버퍼를 지우는"response.sendError()를 호출하는 대신 작동하도록했습니다. [javadoc : 지정된 상태를 사용하여 클라이언트에 오류 응답을 보내고 버퍼를 지 웁니다.] 변경했습니다. 전화 :

response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); 

이제는 내가 자바 스크립트/jquery 쪽에서 기대하는대로 않습니다.

감사합니다.