1

I want to use jquery to submit the form ,the form with text field and file field ,but it just submit the text field "groupId" , I can't submit the groupId with file field . the request header just Content-Type:application/x-www-form-urlencoded; charset=UTF-8

My problem is : can i submit the groupId field and file field once ?If can , what should I do?

the code below

<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>

js code

                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;
                });
Mattia Dinosaur
  • 891
  • 10
  • 29

0 Answers0