我尝试通过JQuery ajax请求将图像上传到php网站。这适用于我的PC,andorid平板电脑和我的iPhone与Firefox,Safari,Internet Explorer,Chrome ...只要我从画廊或文件系统中选择照片。JQuery ajax:使用镀铬上传新照片时出错
在移动设备上有一个很好的功能,如果我选择上传按钮,系统会要求我立即拍照。我可以在我的android平板电脑上使用firefox做到这一点,但它会在平板电脑上使用chrome和使用chrome使用iphone时失败。
的错误是有一点不同:
的Android(银河注10.1,Chrome应用-版本:38.0.2125.114):
error: {
"readyState": 0,
"status":0,
"statusText": "NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'http://peter-pc/upload.php'."
}
IOS(iPhone 4S,Chrome应用,版本: 38.0.2125.59):
error: {
"readyState": 4,
"responseText": "",
"status": 404,
"statusText": "error"
}
我认为404必须是一个错误,因为statusinformation相同的代码从库中上传图片时,工作在同一个浏览器。
我对上传的代码(刚刚添加的异步:假用于测试目的):
var form = $('#imageuploadform');
var formData = new FormData(form[0]);
var action = form.attr("action");
$.ajax({
url: action,
type: 'POST',
data: formData,
async:false,
success: function(response) {
alert("success");
},
error: function(err) {
alert("error: "+JSON.stringify(err, null, 2));
},
dataType: "json",
cache: false,
contentType: false,
processData: false
});
});
希望能对你有所帮助,在此先感谢 彼得