0

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.

joenpc npcsolution
  • 737
  • 4
  • 11
  • 25

1 Answers1

1

I've tried this, and it works.

$(document).on('click', '#download_excel', function(e) {
    window.location="{{ route('yourRoute')}}";
})