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);
},
ajax: function(url, callbacks, opts) {
var form, headers, key, r, type, upCallbacks, val;
var data, headers, key, r, type, upCallbacks, val;
if (opts == null) {
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.open(type || 'get', url, true);
for (key in headers) {
@ -324,10 +324,10 @@
}
$.extend(r, callbacks);
$.extend(r.upload, upCallbacks);
if (typeof form === 'string') {
r.sendAsBinary(form);
if (typeof data === 'string') {
r.sendAsBinary(data);
} else {
r.send(form);
r.send(data);
}
return r;
},
@ -1975,7 +1975,7 @@
return QR.el.dispatchEvent(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) {
e.preventDefault();
}
@ -2042,11 +2042,11 @@
recaptcha_challenge_field: challenge,
recaptcha_response_field: response + ' '
};
form = new FormData();
data = new FormData();
for (name in post) {
val = post[name];
if (val) {
form.append(name, val);
data.append(name, val);
}
}
callbacks = {
@ -2063,7 +2063,7 @@
}
};
opts = {
form: form,
data: data,
type: 'POST',
upCallbacks: {
onload: function() {

View File

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