简体   繁体   English

使用Ajax jQuery上传多个文件

[英]Multiple File Upload Using Ajax Jquery

I already program ajax multiple file upload form but it is not working properly. 我已经编写了ajax多个文件上传表单,但是无法正常工作。

HTML Code: 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>&nbsp;Submit</button>

JQuery Code: 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 Code: PHP代码:

<?php

print_r($_FILES);

?>

How to solve this error. 如何解决这个错误。 I get nothing from PHP response. 我没有从PHP响应中得到任何东西。 I only get Array() response only. 我只得到Array()响应。

Your code works just ensure that your URL is pointing in the right URL address on your server you can see the log on your network tab. 您的代码可以正常工作,只是确保您的URL指向服务器上正确的URL地址,您可以在“网络”标签上看到日志。

You can also try the complete URL path http:// if your in the same domain. 如果您在同一域中,也可以尝试使用完整的URL路径http://

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM