Skip to content

Instantly share code, notes, and snippets.

@jameshoward
Last active March 30, 2017 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jameshoward/8298406 to your computer and use it in GitHub Desktop.
Save jameshoward/8298406 to your computer and use it in GitHub Desktop.
FormData version of MooTools' Request.JSON
Request.FormData = new Class({
Extends : Request.JSON,
send: function(formData) {
this.options.isSuccess = this.options.isSuccess || this.isSuccess;
this.running = true;
var xhr = this.xhr;
xhr.open('POST', this.options.url, true);
xhr.onreadystatechange = this.onStateChange.bind(this);
Object.each(this.headers, function(value, key) {
try {
xhr.setRequestHeader(key, value);
} catch (e) {
this.fireEvent('exception', [key, value]);
}
}, this);
this.fireEvent('request');
xhr.send(formData);
if (!this.options.async) this.onStateChange();
if (this.options.timeout) this.timer = this.timeout.delay(this.options.timeout, this);
return this;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment