Jon*_*ile 2 javascript ajax cgi blob image
-----更新------
我注释掉了window.URL.revokeObjectURL( imgSrc );,现在调用适用于所有浏览器.看起来这个网址在Chrome中过早被撤销了.我仍然很想知道为什么会这样,并且知道我现在处理撤销URL的方式是否存在任何人的意见.我现在撤销最后一个URL,因为下一个URL已加载if (imgSrc) {window.URL.revokeObjectURL( imgSrc );}(imgSrc现在是一个全局变量).
我有一个网站,它使用AJAX调用CGI脚本,输出图像/ jpeg数据,然后使用createObjectURL函数将blob响应设置为页面上图像的src.目前它适用于所有浏览器,但Chrome.
在所有其他浏览器中显示图像,但在Chrome中我收到消息:Failed to load resource: the server responded with a status of 404 (Not Found)后跟一个前缀为的网址blob:.
我尝试过使用webkitURL,但是这给了我同样的错误webkitURL is deprecated.
这是我的AJAX调用的代码:
var filepath = "/babelia.cgi";
xmlhttp=new XMLHttpRequest();
xmlhttp.onload = function(oEvent) {
if (imgSrc) {window.URL.revokeObjectURL( imgSrc );}
var blob = xmlhttp.response;
if (endless) {
imgSrc = (window.URL ? URL : webkitURL).createObjectURL( blob );
document.getElementById("palette").src = imgSrc;
// window.URL.revokeObjectURL( imgSrc );
babel();
}
}
xmlhttp.open("POST",filepath,true);
xmlhttp.responseType = "blob";
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
var info = "location=" + postdata;
if (!landscape) {info += "&flip=portrait";}
xmlhttp.send(info);
Run Code Online (Sandbox Code Playgroud)
你可以在这里看到这个网站:https://babelia.libraryofbabel.info/slideshow.html
小智 7
我也有一些理解blob的问题,这是我的2美分.
旁注:阅读你的问题让我解决了我自己的问题,因为我在撤销后看到了chrome中的404,因为我仍然在img标签上引用了一个已撤销的url.
| 归档时间: |
|
| 查看次数: |
3913 次 |
| 最近记录: |