ajax提交blob,使⽤jQuery的Ajax⽅法作为BLOB检索图像
您不能使⽤jQueryAjax,⽽是使⽤原⽣XMLHttpRequest。
var xhr = new XMLHttpRequest();adystatechange = function(){
if (adyState == 4 && this.status == 200){
//sponse is what you're looking for
sponse);
console.sponse, sponse);
var img = ElementById('img');
var url = window.URL || window.webkitURL;
img.src = sponse);
}}xhr.open('GET', 'jsfiddle/img/logo.png');sponseType = 'blob';xhr.send();
编辑
因此,重新讨论这个主题,使⽤jQuery 3似乎确实是可⾏的。
jQuery.ajax({
url:'images.unsplash/photo-1465101108990-e5eac17cf76d?ixlib=rb-
0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ%3D%3D&s=471ae675a6140db97fea32b55781
cache:false,
xhr:function(){// Seems like the only way to get access to the xhr object
var xhr = new XMLHttpRequest();
return xhr;
},
success: function(data){
var img = ElementById('img');
var url = window.URL || window.webkitURL;
img.src = ateObjectURL(data);
},
error:function(){
}
jquery在线图片});
或
使⽤xhrfield设置ResponseType
jQuery.ajax({
url:'images.unsplash/photo-1465101108990-e5eac17cf76d?ixlib=rb-
0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ%3D%3D&s=471ae675a6140db97fea32b55781
cache:false,
xhrFields:{
responseType: 'blob'
},
success: function(data){
var img = ElementById('img');
var url = window.URL || window.webkitURL;
img.src = ateObjectURL(data);
},
error:function(){
}
});
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论