-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRequest.FormData.HTML.js
More file actions
48 lines (35 loc) · 1.02 KB
/
Request.FormData.HTML.js
File metadata and controls
48 lines (35 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
Request.FormData = new Class({
Extends : Request.HTML,
initialize: function(options) {
this.xhr = new Browser.Request();
this.formData = new FormData();
this.setOptions(options);
this.headers = this.options.headers;
},
append: function(key, value) {
this.formData.append(key, value);
return this.formData;
},
reset: function() {
this.formData = new FormData();
},
send: function() {
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(this.formData);
if (!this.options.async) this.onStateChange();
if (this.options.timeout) this.timer = this.timeout.delay(this.options.timeout, this);
return this;
}
});