JavaScript formdata object is empty for html form post request formdata object empty,form data empty object,javascript formdata object

I'm trying to use formdata object to send form data to my server. I need this because one of my input fields is a file. However the formdata object is blank when I try to send the data to my server, it also prints out "{}". What is the issue? I have jquery updated to 11.1 which supports formdata. Thanks.

  <form enctype="multipart/form-data" name="formName" id="formId">
    <input type="text" name="name" class="form-control" id="name">
  </form>
  <button type="submit" class="btn btn-xl sub">Send Message</button>

  <script>
      $(".sub").click(function(){
         var formElement = document.querySelector("form");
         alert(formElement); //alert message is "[object HTMLFormElement]"
         var d = new FormData(formElement);
         alert(JSON.stringify(d)); //alert message is "{}"
         $.post("/email",d,function(data){
            alert("success!");
         });
      });
  </script>

Server:

/*never reaches endpoint*/
app.post('/email', function(req, res) {
    console.log("entered");
    console.log(req.body) // form fields
    console.log(req.files) // form files
    var resume = req.files;
    email(req.body, resume);
});

https://developer.mozilla.org/en-US/docs/Web/API/FormData/Using_FormData_Objects

Answer:1

I have a form, which allows to select an item from a dropdown list and upload a file. The name and the ID of the item are saved in a Spreadsheet document. Works with one file...but I want to upload ...

I have a form, which allows to select an item from a dropdown list and upload a file. The name and the ID of the item are saved in a Spreadsheet document. Works with one file...but I want to upload ...

  1. handling multiple files in python
  2. handling multiple files in vi
  3. handling multiple files in c
  4. handling multiple files in vi editor
  5. handling multiple files using awk
  6. vim handling multiple files
  7. handling multiple feature files in cucumber
  8. sftp handling multiple files simultaneously

I am following a tutorial [here][1] to make a Facebook like friend tagging system. But the tutorial lacks the "arrow navigating" capability like Facebook. I would like to figure out how to achieve ...

I am following a tutorial [here][1] to make a Facebook like friend tagging system. But the tutorial lacks the "arrow navigating" capability like Facebook. I would like to figure out how to achieve ...

  1. enable arrow navigation in excel
  2. how to enable arrow navigation

I am using Trisquel 7.0. I've some basic knowledge about html and JavaScript. Now I want to save html form data to file (Also interested in loading/filling html form from file). I searched and found ...

I am using Trisquel 7.0. I've some basic knowledge about html and JavaScript. Now I want to save html form data to file (Also interested in loading/filling html form from file). I searched and found ...

  1. saving html form data to text file
  2. saving html form data to xml
  3. saving html form data
  4. saving html form data to xml using javascript
  5. saving html form data to file
  6. saving html form data to xml using php
  7. html saving form values
  8. html form using php

Setup: leftItems & rightItems are arrays of 5 digit ID's. matchedItems is an array of all those ID's - there a lots of results with the same ID. $matches is a div to which I want to append results ...

Setup: leftItems & rightItems are arrays of 5 digit ID's. matchedItems is an array of all those ID's - there a lots of results with the same ID. $matches is a div to which I want to append results ...