Resource interpreted as Document but transferred with MIME type image/jpeg

今天调试程序时遇到这个错

原来是这个写的     url是本地一张图片地址 http://127.0.0.1:8080/file/d5f09608f20d45929f6d0de6e1c3d474.jpg

function download(id,url){
         
                $("#formId" + id).attr("src", url);
                $("#formId" + id).attr("action", url);
                $("#formId" + id).attr("target", "downloadFrame");//iframe的名字
                $("#formId" + id).submit();
            
        }

一直报Resource interpreted as Document but transferred with MIME type image/jpeg
我加一个对图片特殊处理的逻辑 改为

 function download(id,url){
            var tempUrlUpper = url.toUpperCase();
            //GIF .JPEG、*.JPG png
            if(tempUrlUpper.endsWith(".JPG") || tempUrlUpper.endsWith(".PNG") || tempUrlUpper.endsWith(".GIF") || tempUrlUpper.endsWith(".JPEG") ){ var $a = $("<a></a>").attr("href", url).attr("download", "meitu.png"); $a[0].click(); }else { $("#formId" + id).attr("src", url); $("#formId" + id).attr("action", url); $("#formId" + id).attr("target", "downloadFrame");//iframe的名字 $("#formId" + id).submit(); } }

下载的button部分

 

 

 

 

搞定  note  note note 

posted @ 2021-04-19 11:17  agnils  阅读(655)  评论(0编辑  收藏  举报