The Hoops Necessary To Download a CSV using jQuery AJAX

            function downloadFile(fileName, csv) {

                if (navigator.userAgent.indexOf('MSIE') !== -1

                    || navigator.appVersion.indexOf('Trident/') > 0) {

                    var IEwindow = window.open("", "", "Width=0px; Height=0px");

                    IEwindow.document.write('sep=,\r\n' + csv);

                    IEwindow.document.close();

                    IEwindow.document.execCommand('SaveAs', true, fileName);

                    IEwindow.close();

                }

                else {

                    var aLink = document.createElement('a');

                    var evt = document.createEvent("MouseEvents");

                    evt.initMouseEvent("click", true, true, window,

                        0, 0, 0, 0, 0, false, false, false, false, 0, null);

                    aLink.download = fileName;

                    aLink.href = 'data:text/csv;charset=UTF-8,' + encodeURIComponent(csv);

                    aLink.dispatchEvent(evt);

                }

            }

            jQuery(".downloadCSV").on('click', function (e) {

                jQuery.ajax({

                    type: "POST",

                    data: {},

                    url: '/ignitionapi/Dashboard/DownloadCSV',

                    dataType: 'json',

                    success: function (json) {

                        var csv = JSON.parse(json.replace(/"([\w]+)":/g, function ($0, $1) { return ('"' + $1.toLowerCase() + '":'); }));

                        downloadFile('download.csv', encodeURIComponent(csv));

                    }

                });

            });


Download Now


Lihat Sumbernya → The Hoops Necessary To Download a CSV using jQuery AJAX
Download MP3 Terbaru → Andre Matos Mp3 Download


Related Posts To The Hoops Necessary To Download a CSV using jQuery AJAX


The Hoops Necessary To Download a CSV using jQuery AJAX Rating: 4.5 Posted by: kian ws

Search Here

Popular Posts

Total Pageviews

Recent Posts