Skip to content

Instantly share code, notes, and snippets.

@nobodyplace
Created December 8, 2021 08:24
Show Gist options
  • Save nobodyplace/184cc07c19c65c9a47cd8b8dc6dc3997 to your computer and use it in GitHub Desktop.
Save nobodyplace/184cc07c19c65c9a47cd8b8dc6dc3997 to your computer and use it in GitHub Desktop.
$.post({
url: 'makecsv.php',
dataType: 'json',
data: {
data: data
}
}).done(function(response){
if(response != ''){
let uInt8List;
let code = $('#result-output-encode').val();
//エンコードしてBrobにセット
if (code === 'sjis') {
var codes = Encoding.stringToCode(response);
var shiftJisCodeList = Encoding.convert(codes, 'sjis', 'Unicode');
uInt8List = new Uint8Array(shiftJisCodeList);
} else {
uInt8List = response;
}
const blob = new Blob([uInt8List], { type: 'text/csv' });
//リンクを作成してクリック
const a = document.createElement('a');
document.body.appendChild(a);
a.href = window.URL.createObjectURL(blob);
a.download = 'download.csv';
a.click();
}
}).fail(function( jqXHR, textStatus, errorThrown ){
console.error( 'ERROR', jqXHR, textStatus, errorThrown );
}).always(function(response){
//do nothing
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment