I'm working on Laravel Excel using Ajax method. Below is my controller.
public function downloadExcel(){
return Excel::download(new SomeExport(), 'project.xlsx');
}
And this is ajax call.
$(document).on('click', '#download_excel', function(e) {
downloadExcel().then(data => {
//may be need to do some here.
}).catch(error => {})
});
function downloadExcel() {
return new Promise((resolve, reject) => {
$.ajax({
url: `${route.url}/api/...`,
type: 'GET',
headers: {"X-CSRF-TOKEN":route.token},
success: function(data) {
resolve(data)
},
error: function(error) {
reject(error)
},
})
})
}
This work for normal request but not work for ajax. Any advice or guidance on this would be greatly appreciated, Thanks.