1

I'm trying to to trigger pregenerated URL to export CSV as follow:

// call API for CSV export
$( ".buttons-csv" ).click(function(e) {

    var csvURL = csvAPI(dlog);
    $.get( csvURL, function( data ) {
        alert( "Export was performed." );
    });
});

problem is that will not call created csvURL URL to download a file.

I have tried to get it done via

window.location.href = csvURL

but that wasn't work either.

2
  • And what is the url ? Commented May 30, 2019 at 19:39
  • @DontVoteMeDown It generated in csvAPI and looks like http://domain/logs?startdate=2019-05-30&enddate=2019-05-30&filter=string&filter_status=test&_format=csv Commented May 30, 2019 at 20:21

1 Answer 1

4

Downloads don't occur when you use AJAX, only when the browser opens the URL normally in a window. Use window.open() to open a new window that performs the download, while not replacing the current window.

$( ".buttons-csv" ).click(function(e) {

    var csvURL = csvAPI(dlog);
    window.open(csvURL);
});
Sign up to request clarification or add additional context in comments.

Comments

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.