The above code is right as long as you have one file and no other input fields. In case you have more input field and multiple file upload in a single form. One should consider target elements by their IDs instead of type $(":file").
Here is how we can get other files:-
var formData = new FormData();
Here is how we can get data from input fields of form by targeting their IDs.