我有這個代碼的Ajax文件上傳:處理AJAX文件上傳服務器端與金字塔
$('#photo-input:file').change(function() {
var photo = this.files[0];
var caption = $('.photo-caption').val();
type = photo.type;
if (photo.type != 'image/png' && photo.type != 'image/jpg' && !photo.type != 'image/gif' && photo.type != 'image/jpeg') {
alert('Sorry, you may only upload png, jpg, jpeg, or gif images.');
return false;
}
$('.photo-post-submit').click(function() {
var formData = new FormData();
formData.append('photo', photo);
$.ajax({
url: '/post',
type: 'POST',
data: {'photo' : formData, 'caption' : caption},
cache: false,
contentType: false,
processData: false,
success: function() {
}
}, 'json');
});
});
但是,當我打電話request.POST['caption']
或request.POST['photo']
我得到的錯誤:
Not an HTML form submission (Content-Type: application/xml)
什麼錯?
啊,我明白了。這立即解決了問題。謝謝! – Wiz