Forked from wholypantalones/dangolcsvdownloadmanitellyouwhat.js
Created
September 11, 2018 12:34
-
-
Save macielportugal/793025954b2ac6205dec6b46f9bdca5c to your computer and use it in GitHub Desktop.
Force download of csv response from ajax request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.ajax({ | |
url: "path/to/csvData", | |
type: "GET", | |
dataType: "text", | |
success: function (data) { | |
csvData = 'data:application/csv;charset=utf-8,' + encodeURIComponent(data); | |
$("#exportsags").attr({ | |
"href": csvData, | |
"download": "sag_data.csv" | |
}); | |
} | |
}); // ajax |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
var encodedUri = 'data:application/csv;charset=utf-8,' + encodeURIComponent(data);
var link = document.createElement("a");
link.setAttribute("href", encodedUri);
link.setAttribute("download", "relatorio.csv");
link.innerHTML= "Download do Relatório";
document.body.appendChild(link);
link.click();