ajax: form -> data

https://developer.mozilla.org/en/DOM/XMLHttpRequest#send()
formdata is just one type of data that can be sent
This commit is contained in:
James Campos 2012-06-10 15:45:22 -07:00
parent 59aa957d12
commit d6aa2ef83e
2 changed files with 14 additions and 14 deletions

View File

@ -311,11 +311,11 @@
return d.getElementById(id); return d.getElementById(id);
}, },
ajax: function(url, callbacks, opts) { ajax: function(url, callbacks, opts) {
var form, headers, key, r, type, upCallbacks, val; var data, headers, key, r, type, upCallbacks, val;
if (opts == null) { if (opts == null) {
opts = {}; opts = {};
} }
type = opts.type, headers = opts.headers, upCallbacks = opts.upCallbacks, form = opts.form; type = opts.type, headers = opts.headers, upCallbacks = opts.upCallbacks, data = opts.data;
r = new XMLHttpRequest(); r = new XMLHttpRequest();
r.open(type || 'get', url, true); r.open(type || 'get', url, true);
for (key in headers) { for (key in headers) {
@ -324,10 +324,10 @@
} }
$.extend(r, callbacks); $.extend(r, callbacks);
$.extend(r.upload, upCallbacks); $.extend(r.upload, upCallbacks);
if (typeof form === 'string') { if (typeof data === 'string') {
r.sendAsBinary(form); r.sendAsBinary(data);
} else { } else {
r.send(form); r.send(data);
} }
return r; return r;
}, },
@ -1975,7 +1975,7 @@
return QR.el.dispatchEvent(e); return QR.el.dispatchEvent(e);
}, },
submit: function(e) { submit: function(e) {
var callbacks, captcha, captchas, challenge, err, form, m, name, opts, post, reply, response, threadID, val; var callbacks, captcha, captchas, challenge, data, err, m, name, opts, post, reply, response, threadID, val;
if (e != null) { if (e != null) {
e.preventDefault(); e.preventDefault();
} }
@ -2042,11 +2042,11 @@
recaptcha_challenge_field: challenge, recaptcha_challenge_field: challenge,
recaptcha_response_field: response + ' ' recaptcha_response_field: response + ' '
}; };
form = new FormData(); data = new FormData();
for (name in post) { for (name in post) {
val = post[name]; val = post[name];
if (val) { if (val) {
form.append(name, val); data.append(name, val);
} }
} }
callbacks = { callbacks = {
@ -2063,7 +2063,7 @@
} }
}; };
opts = { opts = {
form: form, data: data,
type: 'POST', type: 'POST',
upCallbacks: { upCallbacks: {
onload: function() { onload: function() {

View File

@ -266,14 +266,14 @@ $.extend $,
id: (id) -> id: (id) ->
d.getElementById id d.getElementById id
ajax: (url, callbacks, opts={}) -> ajax: (url, callbacks, opts={}) ->
{type, headers, upCallbacks, form} = opts {type, headers, upCallbacks, data} = opts
r = new XMLHttpRequest() r = new XMLHttpRequest()
r.open type or 'get', url, true r.open type or 'get', url, true
for key, val of headers for key, val of headers
r.setRequestHeader key, val r.setRequestHeader key, val
$.extend r, callbacks $.extend r, callbacks
$.extend r.upload, upCallbacks $.extend r.upload, upCallbacks
if typeof form is 'string' then r.sendAsBinary form else r.send form if typeof data is 'string' then r.sendAsBinary data else r.send data
r r
cache: (url, cb) -> cache: (url, cb) ->
if req = $.cache.requests[url] if req = $.cache.requests[url]
@ -1546,9 +1546,9 @@ QR =
recaptcha_challenge_field: challenge recaptcha_challenge_field: challenge
recaptcha_response_field: response + ' ' recaptcha_response_field: response + ' '
form = new FormData() data = new FormData()
for name, val of post for name, val of post
form.append name, val if val data.append name, val if val
callbacks = callbacks =
onload: -> onload: ->
@ -1562,7 +1562,7 @@ QR =
target: '_blank' target: '_blank'
textContent: 'Connection error, or you are banned.' textContent: 'Connection error, or you are banned.'
opts = opts =
form: form data: data
type: 'POST' type: 'POST'
upCallbacks: upCallbacks:
onload: -> onload: ->