后台代码片段:
UtilHttp.streamContentToBrowser(response, UtilObject.getBytes(list), "application/octet-stream");
后台list:
把list转byte[],再通过io流输出到浏览器,那么在前端通过JS改如何解析呢?
前台Ajax请求代码如下:
$.ajax({
url: "../wfdurl/urlMenuReader.do",
type: "post",
async: false,
data: {},
dataType: "text",
success: function(result) {
console.log(result);
},
error: function(data) {
alert("服务器繁忙,请稍后再试...");
}
});
dataType: "text",得到的数据是乱码,如下图:
求大牛指点啊...
根据大家指点,改成了原生XMLHttpRequest
var oReq = new XMLHttpRequest();
oReq.open("POST", "../wfdurl/urlMenuReader.do", true);
oReq.responseType = "arraybuffer";
oReq.onload = function (oEvent) {
var arrayBuffer = oReq.response; // 注意:不是oReq.responseText
if (arrayBuffer) {
var byteArray = new Uint8Array(arrayBuffer);
console.log('byteArray:' + byteArray);
for (var i = 0; i < byteArray.byteLength; i++) {
//...
}
}
};
oReq.send("type=" + obj.wFType + "&fornocache=QL8M4416");
byteArray: (不是想要的后台list)