title: AJAX not posting to WebMethod
body: <p>The Form:</p>
  
  <pre><code>&lt;form action="upload-document.aspx" onsubmit="sendAndClose();" method="post" enctype="multipart/form-data"&gt;
      &lt;input name="fileToUpload" id="fileToUpload" type="file" /&gt;
      &lt;input type="submit" name="submit" value="Send" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>The AJAX:</p>
  
  <pre><code>    function sendAndClose() {
          currentUrl = location.protocol + '//' + location.host + location.pathname;
  
          var data = new FormData();
          var file = $("#fileToUpload")[0].files[0];
  
          data.append("name", file.name);
          data.append("size", file.size);
          data.append("type", file.type);
          data.append("file", file);
  
          $.ajax({
              type: "POST",
              url: currentUrl + '/Persist',
              dataType: 'json',
              data: data,
              cache: false,
              contentType: false,
              processData: false,
              success: function () {
                  parent.$.fancybox.close();
              },
              error: function (request, error) {
                  alert("[" + error + "] - FAIL: " + request.responseText);
                  parent.$.fancybox.close();
              }
          });
      }
  </code></pre>
  
  <p>The Code-Behind:</p>
  
  <pre><code>[WebMethod]
  public static bool Persist(object data)
  {
      return true;
  }
  </code></pre>
  
  <p>when the form is submitted, it runs the ajax and goes straight to the error callback before entering the webmethod. can anybody tell me why?</p>
  
  <p>also, after the 'var file' I had an alert to show the files name, size, etc... so it gets the file, the problem is that ajax is refusing to comunicate with the code-behind.</p>