jquery ajax post文件、多个文件和文本输入

jquery ajax post文件、多个文件和文本输入,jquery,ajax,file,text,send,Jquery,Ajax,File,Text,Send,大家好,我的html代码: <form action="post.php" enctype="multipart/form-data" method="post"> <input type="text" name="name" id=""><br> <input type="file" name="poster" id="poster"><br> <input type="file" name="scene[]"

大家好,我的html代码:

<form action="post.php" enctype="multipart/form-data" method="post">
   <input type="text" name="name" id=""><br>
   <input type="file" name="poster" id="poster"><br>
   <input type="file" name="scene[]" id="scene" multiple><br>
   <input type="submit" value="POST">
</form>
我研究了其他类似的解决方案,但并没有解决我的问题
对不起,我的英语很差。

你不需要手动操作;如果您只是将
表单
作为doElement提供给
表单数据
构造函数,那么所有表单值都将自动包含在内

还请注意,您应该连接到表单的
submit
事件,而不是submit按钮的
click
事件。您还应该取消使用
async:false
,因为使用它是非常糟糕的做法

说了这么多,试试这个:

$('form').submit(function(e){
    e.preventDefault();
    var form_data = new FormData(this); 

    $.ajax({
        type: 'post',
        url: 'post.php',
        data: form_data,
        cache: false,
        contentType: false,
        processData: false,
        success: function(answ){
            $('#result').html(answ);
        }
    })
})

非常感谢你。新表格数据(本);我没有想过。omgNo的问题,很乐意帮忙。这里是@rorymcrossan,它使用元素的name属性创建表单的name-value对,供您参考。我使用的是ASP.NET,它会弄乱服务器端控件的元素名称。因此,我使用元素的id来使用序列化函数(通过id遍历所有表单控件)构造名称-值对。是否有一种方法可以序列化文本控件并将文件数据附加到formdata?我可以像OP一样手动操作。提前谢谢!
$('form').submit(function(e){
    e.preventDefault();
    var form_data = new FormData(this); 

    $.ajax({
        type: 'post',
        url: 'post.php',
        data: form_data,
        cache: false,
        contentType: false,
        processData: false,
        success: function(answ){
            $('#result').html(answ);
        }
    })
})