title: Uploading image by AJAX, cannot use the serialize() method in jQuery?
body: <p>I found that uploading image with AJAX doesn't seem working with multipart as specified in the form, because my code for checking if it's multipart() never works (in Java);</p>
  
  <pre><code>if (context.isMultiPart() 
  {
      System.out.println("received Multipart data");  
  }
  else
  {
      System.out.println("not multipart data!"); /* my code always prints this message in the upload handler uploadPost() */
  }
  </code></pre>
  
  <p>I have this html form:</p>
  
  <pre><code>&lt;div class="title"&gt;&lt;label&gt;Upload picture!&lt;/label&gt;&lt;/div&gt;
  
  &lt;form method="post" id="imageUploadForm" enctype="multipart/form-data" action="/uploadPost"&gt;
      Please specify file to upload: &lt;input type="file" name="upfile"&gt;&lt;br /&gt;
      &lt;input type="submit" value="submit" id="submitButton"&gt;
  &lt;/form&gt;
  
  &lt;div id="imagedisplay"&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>and the following is my ajax code that sends the image to the upload handler at the address <code>/uploadPost</code>. The uploadPost() method in my Java code first determines whether the upload is multipart or not, however, it seems that ajax does not send the image as multipart. Is it because I use jQuery's serialize() method on the form?</p>
  
  <pre><code>&lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"&gt;&lt;/script&gt;
        &lt;script&gt;
          $(document).ready(function() {
              $('#imageUploadForm').submit(function(evt) {
  
                  var formData = $('#imageUploadForm').serialize();
                  $.post('/uploadPost', formData, uploadResults);
                  evt.preventDefault();
              });
  
              // display the uploaded image on the same page
              function uploadResults(data) {
                      $('#imagedisplay').html("&lt;img src=" + data.url + "" + data.name + "&gt;");
                  }  // end of uploadResults
          });  // end of ready
          &lt;/script&gt;
  </code></pre>