code: function fileUploadXhr(a) {
          var formdata = new FormData();
  
          for (var i=0; i < a.length; i++) {
              formdata.append(a[i].name, a[i].value);
          }
  
          if (options.extraData) {
              for (var p in options.extraData)
                  if (options.extraData.hasOwnProperty(p))
                      formdata.append(p, options.extraData[p]);
          }
  
          options.data = null;
  
          var s = $.extend(true, {}, $.ajaxSettings, options, {
              contentType: false,
              processData: false,
              cache: false,
              type: 'POST'
          });
          
          if (options.uploadProgress) {
              // workaround because jqXHR does not expose upload property
              s.xhr = function() {
                  var xhr = jQuery.ajaxSettings.xhr();
                  if (xhr.upload) {
                      xhr.upload.onprogress = function(event) {
                          var percent = 0;
                          var position = event.loaded || event.position; /*event.position is deprecated*/
                          var total = event.total;
                          if (event.lengthComputable) {
                              percent = Math.ceil(position / total * 100);
                          }
                          options.uploadProgress(event, position, total, percent);
                      };
                  }
                  return xhr;
              };
          }
  
          s.data = null;
            var beforeSend = s.beforeSend;
            s.beforeSend = function(xhr, o) {
                o.data = formdata;
              if(beforeSend)
                  beforeSend.call(o, xhr, options);
          };
          $.ajax(s);
      }
docs: XMLHttpRequest Level 2 file uploads (big hat tip to francois2metz)