title: Blueimp File Uploader is submitting multiple times
body: <p>I didn't build this part of our site but because the other developer has been pulled into another project it's my job to fix this issue. Basically we're using the basic blue imp file uploader plugin to submit files via ajax. When I pick a file for the first time and upload it everything works fine. When I pick a new file and upload it, it submits twice. One with the first file and one with the second file. If I pick a new file after that it will submit 3 times, etc. The same thing happens if I discard the file instead of upload it. I can't, for the life of me figure out what's triggering it to run multiple times and I haven't had any help online. </p>
  
  <pre><code>&lt;section class="add-document editable"&gt;
            &lt;form id="add-new-doc" enctype="multipart/form-data" action="" data-project="projectid" class="document-upload"&gt;
              &lt;div class="hidden"&gt;
                &lt;div class="row"&gt;
                  &lt;div class="col-xs-12"&gt;
                    &lt;h3 class="editcue"&gt;Add a new document&lt;/h3&gt;
                  &lt;/div&gt;
                &lt;/div&gt;
                &lt;div class="row"&gt;
                  &lt;div class="col-xs-12 col-sm-4"&gt;
                    &lt;label for="item-title"&gt;Document Title&lt;/label&gt;
                  &lt;/div&gt;
                  &lt;div class="col-xs-12 col-sm-8"&gt;
                    &lt;input type="text" name="item-title" placeholder="Title" value="" data-type=""&gt;
                  &lt;/div&gt;
                &lt;/div&gt;
                &lt;div class="row"&gt;
                  &lt;div class="col-xs-12 col-sm-4"&gt;
                    &lt;label for="file"&gt;Related Document&lt;/label&gt;
                  &lt;/div&gt;
                  &lt;div class="col-xs-12 col-sm-8"&gt;
                    &lt;div class="upload-button"&gt;&lt;span class="alt"&gt;Selected file: Individual_Check_Stub2015_11_13_04_15_25_218.PDF&lt;/span&gt;
                      &lt;input type="file" id="fileupload" name="file" accept=".doc,.docx,.pdf,.txt,.jpg,.png,.xls,.xlsx,.csv,.ppt,.zip" data-url=""&gt;
                    &lt;/div&gt;
                  &lt;/div&gt;
                &lt;/div&gt;
                &lt;div class="row"&gt;
                  &lt;div class="col-xs-12 col-sm-4"&gt;
                    &lt;label for="expr-or-issue-date"&gt;Date (optional)&lt;/label&gt;
                  &lt;/div&gt;
                  &lt;div class="col-xs-12 col-sm-8"&gt;
                    &lt;input type="date" name="expr-or-issue-date" value="" data-type=""&gt;
                  &lt;/div&gt;
                &lt;/div&gt;
                &lt;div class="row"&gt;
                  &lt;div class="col-xs-12 col-sm-4"&gt;
                    &lt;label for="restrict-to-subsidiary"&gt;Restrict this document (optional)&lt;/label&gt;
                  &lt;/div&gt;
                  &lt;div class="col-xs-12 col-sm-8"&gt;
                    &lt;!-- multi-select filterable select--&gt;
                    &lt;select data-placeholder="Choose a Subsidiary" name="restrict-to-subsidiary" multiple="" data-url="../_res/js/json/subsidiary-doc.json" class="select-restrict select2-hidden-accessible" tabindex="-1" aria-hidden="true"&gt;&lt;option value="itemid-001" title="itemid-001"&gt;Appleton Corporation&lt;/option&gt;&lt;option value="itemid-003" title="itemid-003"&gt;Daniel O'Connell's Sons&lt;/option&gt;&lt;/select&gt;&lt;span class="select2 select2-container select2-container--default" dir="ltr" style="width: 503px;"&gt;&lt;span class="selection"&gt;&lt;span class="select2-selection select2-selection--multiple" role="combobox" aria-autocomplete="list" aria-haspopup="true" aria-expanded="false" tabindex="-1"&gt;&lt;ul class="select2-selection__rendered"&gt;&lt;li class="select2-search select2-search--inline"&gt;&lt;input class="select2-search__field" type="search" tabindex="0" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" role="textbox" placeholder="Choose a Subsidiary" style="width: 469px;"&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="dropdown-wrapper" aria-hidden="true"&gt;&lt;/span&gt;&lt;/span&gt;
                    &lt;!-- end multi-select--&gt;
                  &lt;/div&gt;
                &lt;/div&gt;
                &lt;!-- Edit Actions: Save or Cancel Edit Buttons--&gt;
                &lt;div class="actions"&gt;
                  &lt;div class="row"&gt;
                    &lt;div class="col-xs-12 col-sm-4"&gt;
                      &lt;div class="discarddoc"&gt;&lt;span&gt;Discard document&lt;/span&gt;&lt;/div&gt;
                    &lt;/div&gt;
                    &lt;div class="col-xs-12 col-sm-4"&gt;
                      &lt;div class="newdoc"&gt;&lt;span&gt;Upload document
                          &lt;!-- End C-02--&gt;&lt;/span&gt;&lt;/div&gt;
                    &lt;/div&gt;
                    &lt;div class="col-xs-12 col-sm-4"&gt;&lt;/div&gt;
                  &lt;/div&gt;
                &lt;/div&gt;
                &lt;!-- End edit actions--&gt;
              &lt;/div&gt;
            &lt;/form&gt;
          &lt;/section&gt;
  </code></pre>
  
  <p>Here is the js</p>
  
  <pre><code>// upload documents on submit
  function uploadThis(){
      var $form = $('input[type=file]').closest('form'),
              userid = $form.data('user'),
              url = $form.attr('action'),
              uploadButton = $form.find('.new-doc span');
  
              $('input[type=file]').fileupload({
  
                url: url,
                multipart: true,
                singleFileUploads: true,
                add: function (e, data) {
                          data.context = $form.find('.newdoc').click(function () {
                              console.log($(this));
                              data.submit();
                              return false;
                          });
                },
                 change: function (e, data){
                      if($(this).attr('id') === "image-input"){}
                      else{
                          var thisform = $(this).closest('form');
                          $.each(data.files, function(index,file){
                                  data.context = thisform.find('.upload-button span').text('Selected file: ' + file.name);
                          });
                          }
                  },
                done: function (e, data) {
                          var thisform = $(this).closest('form');
                                   data.context = thisform.find(".upload-button input").find(".files").empty();
  
                          $(this).wrap('&lt;form&gt;').closest('form').get(0).reset();
                            $(this).unwrap();
                                    },
  
                                    stop: function(e, data) {
  
  
                                              },
                                    failed: function (e, data) {
                                      data.context.text('Unable to upload document.');
                                    }
              });
  
  }
  
  // document uploads 
  $('.document-upload').each(function(){
  
      var userid = $(this).data('user');
  
      //some code retracted to keep it simpler
  
      uploadThis();
  
  });
  // end document uploads
  
  // discard doc
  $('#add-new-doc .discarddoc').on('click', function(e){
      e.preventDefault();
  
      var $this = $(this),
              $form = $(this).closest('form');
  
      $form[0].reset();
      $form
          .find('.upload-button span')
          .text('Select Document');
  });
  </code></pre>
  
  <p>Sorry for the formatting I tried to fix it up as much as possible. Any insight would be amazing. Thanks </p>