我看不出为什么我的代码无效。我的HTML是:
<form name="admin_image" action="/index.php" method="post"enctype="multipart/form-data">
<input class="editor" type="text" name="image_title_100502002" value="" placeholder="Bildtitel">
<label for="fileToUpload_100502002" class="fileUpload">
<input type="file" name="fileToUpload" id="fileToUpload_100502002">
</label>
<input type="submit" name="delete_image_100502002" value="Bild löschen">
<span data-name="remove_image_100502002">Abbrechen</span>
<input class="ajax_submit_image" type="submit" name="submit_image_100502002" value="Speichern">
</form>
当提交没有ajax的表单时,一切正常,服务器端可以处理$ _FILES数组,当通过ajax提交表单时,它不起作用,即使chrome dev工具显示xhr beeing成功。 这是我的Jquery ajax:
// send cms image via ajax
$("input.ajax_submit_image").click(function(event){
//dont submit form on click
event.preventDefault();
//save form parent in variable
var thisform = $(this).parent();
//set ajax data
var formdata = new FormData(thisform[0]);
// send ajax
$.ajax({
data: formdata,
processData: false,
contentType: false,
error: function() {
alert('an ajax error occured');
},
success: function() {
//return updated content
// $('form.show').next('div.currentcontent').empty().append('TEST');
//close the form after ajax submission
thisform.toggleClass('show');
// hide overlay when form is hidden
$('#cms_overlay').removeClass('show');
//reset id when current content is submitted when ajax finished
CMS.currenteditid= undefined;
},
type: 'POST'
});
})
有谁知道为什么它不适用于ajax?提前谢谢!
答案 0 :(得分:1)
我从我的应用中删除了
<input type="file" id="input_files" name="input_files[]" multiple="true" onchange="uploader.loadFiles(event);" />
----
// load files, var files = new Array()
var loadFiles = function(event)
{
files = event.target.files;
}
嗯,剩下的处理工作是在另一个地方完成的,但要管理文件,你需要应用类似的东西。