你们有遇到过手机浏览器不兼容图片上传的问题吗?
部分手机浏览器上传图片时,服务器接收到的图片是NULL。
如下是JS代码,问一下怎么兼容微信自带的浏览器
部分手机浏览器上传图片时,服务器接收到的图片是NULL。
如下是JS代码,问一下怎么兼容微信自带的浏览器
function uploadImg(_this){
var suxFix = _this.id.match(/\_(\d+)/);
var idx = suxFix[1];
var next = parseInt(idx)+1;
lrz(_this.files[0], {width: 1000}, function (results) {
//console.log(results); //debug
var xhr = new XMLHttpRequest();
var data = {
base64: results.base64,
size: results.base64.length
};
xhr.open("POST", baseUrl_online+"bs/file/upload/image");
xhr.setRequestHeader("Content-Type", "multipart/form-data; charset=utf-8");
xhr.onload = function () {
if (xhr.status >= 200 && xhr.status <300 || xhr == 304) {
var result = JSON.parse(xhr.response);
$("#picimg_"+idx).attr("src",result.data).css("z-index","1");
$("#pic_"+next).css("display","");
}
};
xhr.send(JSON.stringify(data));
});
}
解决方案