Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

chern123's avatar

File Download using AJAX?

I am using Laravel Excel to generate a spreadsheet. The method that generates to the spreadsheet is linked to a route:

export/messages

This works fine if I navigate to it manually in the browser. However, I am using the VueJS Router for the actual navigation of the app, as well as the front-end, and thus if I use a method such as this:

            export: function() {
                this.$http.get('export/messages').then(function(response) {
                    return response; //I've tried doing several things here, this was my last desperate attempt
                });
            }

The actual file download will not trigger. Any suggestions/tips on how to get this to work?

0 likes
1 reply
chern123's avatar
chern123
OP
Best Answer
Level 3

Ended up realizing that it simply won't work via an AJAX call - had to use window.location instead, which isn't ideal, but still works.

Please or to participate in this conversation.