[英]JQuery FormData ajax file upload not working
I can't see why my code is not working.我不明白为什么我的代码不起作用。 My html is:
我的 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>
when submitting the form without ajax, everything works and the server side can process the $_FILES array, when submitting the form via ajax, it doesnt work, even though chrome dev tool shows the xhr beeing successfull.当提交没有ajax的表单时,一切正常,服务器端可以处理$_FILES数组,当通过ajax提交表单时,它不起作用,即使chrome dev工具显示xhr beeing成功。 This is my Jquery ajax:
这是我的 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'
});
})
Does anyone see why it does not work with ajax ?有没有人明白为什么它不适用于 ajax ? Thanks in advance!
提前致谢!
I cut it from my app我从我的应用程序中剪下它
<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;
}
Well, the rest of processing is done in another place, but to manage files you'll need to apply something like that.好吧,其余的处理在另一个地方完成,但要管理文件,您需要应用类似的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.