我已经编写了ajax多文件上传表单,但它无法正常工作。
HTML代码:
<form method="post" id="postfrom" enctype="multipart/form-data">
<input type="file" name="file" id="file" class="inputfile" multiple accept=".mp4, .mov, .m4v, .MPEG-4, .gif, .jpg, .png"/>
</form>
<button type="button" class="btnb btnb-primary" id="submitpost"><i class="fa fa-paper-plane-o" aria-hidden="true"></i> Submit</button>
JQuery代码:
$(document).on("click", "#submitpost", function(){
$("#postfrom").submit();
});
$("#postfrom").on('submit', function(e){
e.preventDefault();
$.ajax({
url : "/php/post_submit.php",
type: "POST",
cache: false,
contentType: false,
processData: false,
data : new FormData(this),
success: function(response){
$('.result').html(response);
alert(response);
},
error: function (request, status, error) {
alert(request.responseText);
}
});
});
PHP代码:
<?php
print_r($_FILES);
?>
如何解决此错误。我从PHP响应中得不到任何结果。