title: Need help to write a Jquery $.ajax request equivalent to an XHR request
body: <p>Working XHR request that sends a file
  with all required request headers set.</p>
  
  <pre><code>var upload = function (file) {
      var xhr = new XMLHttpRequest();
      xhr.open('POST', '/Admin/Upload', true);
      xhr.setRequestHeader('X-Filename', file.name);
      xhr.setRequestHeader('pageid', pageid);
      xhr.setRequestHeader('catid', catid);
      xhr.send(file);
  }
  </code></pre>
  
  <p>Trying to get the below working (Using jQuery 1.7.2)</p>
  
  <pre><code>var xhr = new XMLHttpRequest();
  
  var upload = function (file, xhr) {
      $.ajax
      ({
          url: '/Admin/Upload',
          beforeSend: function (xhr) {
              xhr.setRequestHeader('X-Filename', file.name);
              xhr.setRequestHeader('pageid', pageid);
              xhr.setRequestHeader('catid', catid);
  
          },
          data: file,
          success: function (data) {
  
              alert('Load was performed.');
          }
  
      });
  }
  </code></pre>
  
  <p><strong>Update:</strong> 
  Ok, so I have progressed a bit and the request now actually hits the action method,
  however there is no data in the input stream and all the file key arrays are null,
  so the actual file data does no appear to be going through. The request headers are coming through fine. The (data: file) is different I presume to xhr.send(file) ?  </p>
  
  <p>Now using this:</p>
  
  <pre><code>var upload = function (file) 
  {
      $.ajax
      ({
          url: "/Admin/Upload",
          headers: { catid: catid, pageid: pageid },
          processData: false,
          data: file,
          success: function (data) {
  
              alert('Load was performed.');
          }
  
      });
  }
  </code></pre>