Export excel using XMLHttpRequest

problem description

use XMLHttpRequest to export excel, but responseType may be blob, or json

related codes

    var xhr = new XMLHttpRequest();
    xhr.open("get", url, true);
    xhr.responseType = "blob"; // blob  blob 
    xhr.onload = function () {
        console.log(xhr)
        if (this.status === 200) {
            var blob = this.response;
            var reader = new FileReader();
            reader.readAsDataURL(blob); // base64ahref
            reader.onload = function (e) {
                var a = document.createElement("a"); // a
                a.download = name + ".xls";
                a.href = e.target.result;
                $("body").append(a); // firefoxclick
                a.click();
                $(a).remove();
            };
        }
    }
    xhr.send(); // ajax

what result do you expect? What is the error message actually seen?

response may not be a file, but a wrong prompt (there is a mistake in the export process or there is no data export). At this time, what if responseType has been set to blob? Can responseType be defined only before the request is made?

Mar.30,2021

xhr.getResponseHeader("Content-Type")// json blodstringjson
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3df02-34783.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3df02-34783.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?