• 使用XMLHttpRequest处理异步请求返回的图片等二进制文件


    封装的Ajax没有接受文件的类型 所以要用传统的 XMLHttpRequest来处理

    function ShowPdf() {
                var url = "/ChannelLiquidation/ShowPdf.ashx?PdfName=<%=PdfName %>&pdfFolder=<%=PdfFolder %>";
                var xhr = null;;
                if (window.XMLHttpRequest) {// code for IE7, Firefox, Opera, etc.
                    xhr = new XMLHttpRequest();
                }
                else if (window.ActiveXObject) {// code for IE6, IE5
                    xhr = new ActiveXObject("Microsoft.XMLHTTP");
                }
                if (xhr != null) {
                    xhr.onreadystatechange = false;
                    xhr.open('GET', url, true);
                    xhr.responseType = "blob";
                    xhr.setRequestHeader("client_type", "DESKTOP_WEB");
                    xhr.setRequestHeader("desktop_web_access_key", Math.random().toString());
                    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);
                            img.style.cssText = " 90%; float: left";
                            img.setAttribute("onerror","this.src='../Assets/img/notBill.jpeg'");
                            $("#div_imgcontainer").html(img);
                        }
                    }
                    xhr.send();
                }
            }
            $(function () {ShowPdf();})

  • 相关阅读:
    零基础学Python-第一章 :Python介绍和安装-02.Python的发展历史与版本
    零基础学Python_汇总贴
    零基础学Python-第一章 :Python介绍和安装-01.Python语言的特点
    Spring cloud微服务安全实战-3-11API安全机制之登录
    iOS play video
    Http Live Streaming 实现iphone在线播放视频[转]
    UIWebView分页显示
    ios7适配--uitableviewcell选中效果
    ios7 设置status bar风格
    ios7适配--隐藏status bar
  • 原文地址:https://www.cnblogs.com/ccmsalome/p/7274552.html
Copyright © 2020-2023  润新知