<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>ajax 请求二进制流图片</title>
<script src="Scripts/jquery.min.js" type="text/javascript"></script>
<script src="Scripts/boot.js" type="text/javascript"></script>
</head>
<body>
<form id="form1" runat="server">
<div id="imgcontainer">
</div>
</form>
</body>
</html>
<script language="javascript" type="text/javascript">
var url = bootPATH + "../server/images/1.png";
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = "blob";
xhr.setRequestHeader("client_type", "DESKTOP_WEB");
xhr.onload = function () {
if (this.status == 200) {
var blob = this.response;
var img = document.createElement("img");
img.onload = function (e) {
window.URL.revokeObjectURL(img.src);
};
img.src = window.URL.createObjectURL(blob);
$("#imgcontainer").html(img);
}
}
xhr.send();
</script>