我嘗試通過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
});
});
希望能對你有所幫助,在此先感謝 彼得