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.

1

1 Answer 1

1

I've tried this, and it works.

$(document).on('click', '#download_excel', function(e) {
    window.location="{{ route('yourRoute')}}";
})
Sign up to request clarification or add additional context in comments.

1 Comment

But this is not ajax, not answering the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.