我已經得到這個奇怪的錯誤,我只是無法弄清楚遺漏的類型錯誤:無法讀取的不確定
這裏財產「0」是我當前的代碼:
function addBackground() {
var penguin_id = getPenguinID();
var file = $('#image_form')[0].files[0];
console.log('Image Getting Uploaded');
var formData = new FormData();
formData.append('file', file);
$.ajax({
url: "custBG.php",
type: "POST",
data: formData,
cache: false,
contentType: false,
processData: false,
mimeType: 'multipart/form-data'
}).done(function(data) {
if (data.status == 0) {
console.log('Image Has Been Uploaded');
addBGItem(70000 + penguin_id);
} else {
console.log(data.message);
}
});
}
這裏表格
<form id="image_form">
<div class="left">
<img id="img-uploaded" src="http://dummyimage.com/210x210/dbdbdb/7e7f80.png" alt="your image" />
</div>
<div class="right">
<input type="file" name="imageToUpload" accept=".png,.jpeg,.jpg,.gif" onchange="validate_image()">
<span class="btn btn-large btn-alpha" onclick="addBackground()">Upload Image</span>
</span>
</div>
</form>
我不確定發生了什麼,但任何人都可以幫助我解決問題。
哪行代碼會給你這個錯誤? –
它不告訴我,但這裏http://prntscr.com/bhrmx9 –
它確實:行2(inline-fe9e22321d.js:** 2 **),我認爲是'var file = $('# image_form')[0] .files [0];'由於錯誤的性質。介意在DOM中的#image_form中發佈什麼內容? –