我使用以下代码上传了 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)
怎么了?