2016-10-05 5 views
-2

엑셀 파일을 다운로드하기위한 AngularJS 코드를 개발했습니다. 이 코드는 Chrome과 IE에서 잘 작동합니다. 하지만 Firefox에서는 작동하지 않습니다. 서버에서 아무런 문제없이 응답이옵니다. 여기에 내 코드,Angular JS 엑셀 파일 다운로드가 파이어 폭스에서 작동하지 않습니다

var did = "someid"; 
var url = '/downloadAsExcel'; 
$http({method: 'POST', url: url, data:did,headers: {'Content-type': 'application/json'},responseType: 'arraybuffer'}) 
.success(function(data, status, headers, config) { 
    var blob = new Blob([data],{type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}); 
    var link = document.createElement('a'); 
    link.href = window.URL.createObjectURL(blob); 
    var fileName = headers('Content-Disposition').split(";")[1]; 
    fileName = fileName.trim().split("=")[1]; 
    var downloadName = (fileName != 'undefined') ? fileName : "DefaultName"; 
    link.download = downloadName; 
    link.click(); 
}) 
.error(function(data, status) { 
    console.log("Some thing went wrong "+status); 
}); 

어떤 도움을 주시기 바랍니다

감사합니다, JK

+1

"작동하지 않음"오류를 정의 하시겠습니까? Firefox가 충돌합니까? 우주는 끝났어? 다른? – Gagravarr

+0

버튼을 클릭하면 파일이 다운로드되지만 실제로 그런 일은 일어나지 않습니다. 그리고 코드를 디버깅 할 때 응답 코드는 200입니다. –

+1

@Rama Krishna Guntuka : 여기서 apache-poi가 사용되는 부분은 어디입니까? 문제 : 당신은'A' 엘리먼트를 생성하고 있지만 DOM에 어딘가에 추가하지 마십시오. 'do ... link.download = downloadName; $ ("body"). append (link); link.click(); ...'. –

답변

1

이 악셀의 도움을 복용 후 솔루션입니다.

var did = "someid"; 
var url = '/downloadAsExcel'; 
$http({method: 'POST', url: url, data:did,headers: {'Content-type': 'application/json'},responseType: 'arraybuffer'}) 
.success(function(data, status, headers, config) { 
var blob = new Blob([data],{type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}); 
var link = document.createElement('a'); 
link.href = window.URL.createObjectURL(blob); 
var fileName = headers('Content-Disposition').split(";")[1]; 
fileName = fileName.trim().split("=")[1]; 
var downloadName = (fileName != 'undefined') ? fileName : "DefaultName"; 
link.download = downloadName; 
if(document.body != null){ document.body.appendChild(link); } 
link.click(); 
}) 
.error(function(data, status) { 
console.log("Some thing went wrong "+status); 
}); 
관련 문제