2
4

1 回答 1

1

Well, just need to set responseType to arraybuffer for the ajax request. Since, the jQuery does not supports that dataType, have to use traditional Javascript Ajax

For more Info see Sending and Receiving Binary Data

function ajaxFileStream() {
    var url = "/Home/GetFileStream";
    var oReq = new XMLHttpRequest();
    oReq.open("GET", url, true);
    oReq.responseType = "arraybuffer";

    oReq.onload = function (oEvent) {
        console.log(oReq.response);
        var blob = new Blob([oReq.response], { type: "application/pdf" });
        var win = window.open('', '_blank');
        var URL = window.URL || window.webkitURL;
        var dataUrl = URL.createObjectURL(blob);
        win.location = dataUrl;
    };
    oReq.send();
}

Thanks, bUKaneer that linked helped a lot.

于 2014-07-10T11:53:17.597 回答