ExtJS를 사용하여 프로그램 용 클라이언트 측을 빌드합니다. 서버에 Ajax 요청을 보내고 응답 파일 (XLS 또는 PDF와 같은 일반 텍스트 파일이 아닌 이진 파일)을 가져 오는 상황이 있습니다. ExtJS가 반환 한 파일을 어떻게 얻을 수 있습니까? (파일을 다운로드하여 클라이언트에 저장할 수 있다는 의미입니까?) 응답에 바이너리 데이터가 포함되어 있고 디코딩 할 수 없기 때문에 var result = Ext.decode(response.responseText)
을 사용하여 결과를받을 수 없습니다.응답 파일 사용 ExtJS
Ajax 호출은 매우 간단합니다 :
public void sendFile(HttpServletResponse response, String filePath) {
def file = new File(filePath);
response.setContentType("application/octet-stream");
response.setHeader("Content-disposition", "attachment;filename=${file.getName()}");
response.outputStream << file.newInputStream();
}
너무 감사 :
Ext.Ajax.request({
url : 'myController/exportFile',
method : 'GET',
success : function(response, opts) {
// What should I do to get the file?
},
failure : function(response, opts) {
alert('Export file failed!')
}
});
파일을 여기에 돌아가 내 서버 작업입니다!
좋은 답변입니다! 너는 최고야 !! 나는이 오랜 시간을 보았고이 게시물 만이 나에게 적절한 답을 주었다! – davs
@ amol 당신이 도와주세요 제발 [여기] (http://stackoverflow.com/questions/8505995/itextsharp-generated-pdf-how-to-prompt-a-user-to-choose-where-to-save) – Armance