繁体   English   中英

使用Ajax jQuery上传多个文件

[英]Multiple File Upload Using Ajax Jquery

我已经编写了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>&nbsp;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响应中得到任何东西。 我只得到Array()响应。

您的代码可以正常工作,只是确保您的URL指向服务器上正确的URL地址,您可以在“网络”标签上看到日志。

如果您在同一域中,也可以尝试使用完整的URL路径http://

在此处输入图片说明

暂无
暂无

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

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