title: submitting a form in a modal with ajax using laravel
body: <p>I'm trying to upload both text and files through a form loaded inside a modal and submit it using ajax (I'm using Laravel 5.2) and I can't figure out why it doesn’t working. I have tried many solutions found here and through a search engine.</p>
  
  <p><strong>A simple form (this form is loaded in a modal)</strong></p>
  
  <pre><code>&lt;form id="registerForm" enctype="multipart/form-data" class="form-horizontal" role="form" method="POST"&gt;
  
  
  &lt;div class="form-group"&gt;
  &lt;label class="col-md-4 control-label"&gt;Name&lt;/label&gt;
  &lt;div class="col-md-6"&gt;
  &lt;input type="text" class="form-control" name="name" id="name"&gt;
  
  &lt;div class="form-group"&gt;
  &lt;label class="control-label col-md-4" for="pwd"&gt;Choose File&lt;/label&gt;
  &lt;div class="col-md-6"&gt; 
  &lt;input type="file" class="form-control" id="fileProfPic" name="prof_pic"&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;button type="submit" id="registerButtonModal" class="btn btn-primary"&gt;&lt;i class="fa fa-btn fa-user"&gt;&lt;/i&gt;Register&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>.js</strong></p>
  
  <pre><code>$("#registerButtonModal").click(function(){
      $('#registerForm').submit(function (e) {
          e.preventDefault();
          var formData = new FormData($('#registerForm')[0]);
  
          $.ajax({
              url: 'register',
              type: 'POST',
              data: formData,
              success: function(msg){
                  alert(msg);
              }
              contentType: false,
              processData: false
  
          });
          });
  });
  </code></pre>
  
  <p><strong>route</strong></p>
  
  <pre><code> Route::post('register',[
          'uses' =&gt; 'AdminController@postRegister',
          'as' =&gt; 'postRegister']);
  </code></pre>
  
  <p><strong>controller //just trying to make it work</strong></p>
  
  <pre><code>public function postRegister(Request $request)
      {
          return "success";
      }
  </code></pre>