Javascript 是否可以一次性提交文件和表单中的其他字段?

Javascript 是否可以一次性提交文件和表单中的其他字段?,javascript,jquery,html,forms,Javascript,Jquery,Html,Forms,我想使用jquery提交表单,带有文本字段和文件字段的表单,但它只提交文本字段“groupId”,我不能提交带有文件字段的groupId。 请求头刚刚打开 内容类型:应用程序/x-www-form-urlencoded;字符集=UTF-8 我的问题是:我可以提交groupId字段和file字段一次吗?如果可以,我应该怎么做? 下面的代码 <form id="submitForm" > <div class="

我想使用jquery提交表单,带有文本字段和文件字段的表单,但它只提交文本字段“groupId”,我不能提交带有文件字段的groupId。 请求头刚刚打开 内容类型:应用程序/x-www-form-urlencoded;字符集=UTF-8

我的问题是:我可以提交groupId字段和file字段一次吗?如果可以,我应该怎么做?

下面的代码

<form  id="submitForm"  >                      
           <div class="form-group">
             <label for="exampleInputEmail1" >groupId</label>
             <input type="text" name="groupId" class="form-control" >
           </div>

          <div class="form-group">
             <label for="exampleInputFile" >File input</label>
             <input type="file" name="file" class="form-control-file" id="exampleInputFile" aria-describedby="fileHelp">
                 <small id="fileHelp" class="form-text text-muted">This is some placeholder block-level help text for the above input. It's a bit lighter and easily wraps to a new line.</small>
          </div>
          <button id="newItemSubmitButton" type="submit" class="btn btn-primary">submit</button>
          <button type="button" class="btn btn-default" >cancel</button>
    </form>

你至少试过谷歌搜索一次吗?看看这是否有用。。我搜索过很多次,我只知道那个包含多部分/表单数据的文件,我读过rfc 1867,但它只是概述了这个文件。参考和多部分数据。你至少尝试过谷歌搜索一次吗?看看这是否有帮助。。我搜索过很多次,我只知道那个包含多部分/表单数据的文件,我读过RFC1867,但它只是概述了这个文件
                var submitForm = $('#submitForm');
                $("#newItemSubmitButton").click(function (e) {
                    console.log("submit");  
                        e.preventDefault();
                        console.log("after preventDefault");
                        $.ajax({
                            data:submitForm.serialize() ,
                            url: "./testSubmit",
                            type: "post",
                            success: function (data) {
                                // $("#form_output").html(data);
                                console.log("hello");
                            },
                            error: function (jXHR, textStatus, errorThrown) {
                                alert(errorThrown);
                            }
                        });

                    $('#newItem').modal('hide');
                    return false;
                });