$.formData

This commit is contained in:
James Campos 2012-06-10 16:28:22 -07:00
parent f7a9fb526e
commit e770265266
2 changed files with 24 additions and 11 deletions

View File

@ -310,6 +310,19 @@
id: function(id) { id: function(id) {
return d.getElementById(id); return d.getElementById(id);
}, },
formData: function(arg) {
var fd, key, val;
if (arg instanceof HTMLElement) {
fd = new FormData(arg);
} else {
fd = new FormData();
for (key in arg) {
val = arg[key];
fd.append(key, val);
}
}
return fd;
},
ajax: function(url, callbacks, opts) { ajax: function(url, callbacks, opts) {
var data, headers, key, r, type, upCallbacks, val; var data, headers, key, r, type, upCallbacks, val;
if (opts == null) { if (opts == null) {
@ -1979,7 +1992,7 @@
return QR.el.dispatchEvent(e); return QR.el.dispatchEvent(e);
}, },
submit: function(e) { submit: function(e) {
var callbacks, captcha, captchas, challenge, data, err, m, name, opts, post, reply, response, threadID, val; var callbacks, captcha, captchas, challenge, data, err, m, opts, post, reply, response, threadID;
if (e != null) { if (e != null) {
e.preventDefault(); e.preventDefault();
} }
@ -2046,13 +2059,7 @@
recaptcha_challenge_field: challenge, recaptcha_challenge_field: challenge,
recaptcha_response_field: response + ' ' recaptcha_response_field: response + ' '
}; };
data = new FormData(); data = $.formData(post);
for (name in post) {
val = post[name];
if (val) {
data.append(name, val);
}
}
callbacks = { callbacks = {
onload: function() { onload: function() {
return QR.response(this.response); return QR.response(this.response);

View File

@ -265,6 +265,14 @@ $.extend $,
cb JSON.parse e.newValue if e.key is "#{Main.namespace}#{key}" cb JSON.parse e.newValue if e.key is "#{Main.namespace}#{key}"
id: (id) -> id: (id) ->
d.getElementById id d.getElementById id
formData: (arg) ->
if arg instanceof HTMLElement
fd = new FormData arg
else
fd = new FormData()
for key, val of arg
fd.append key, val
fd
ajax: (url, callbacks, opts={}) -> ajax: (url, callbacks, opts={}) ->
{type, headers, upCallbacks, data} = opts {type, headers, upCallbacks, data} = opts
r = new XMLHttpRequest() r = new XMLHttpRequest()
@ -1548,9 +1556,7 @@ QR =
recaptcha_challenge_field: challenge recaptcha_challenge_field: challenge
recaptcha_response_field: response + ' ' recaptcha_response_field: response + ' '
data = new FormData() data = $.formData post
for name, val of post
data.append name, val if val
callbacks = callbacks =
onload: -> onload: ->