smarter ajax type checking

This commit is contained in:
James Campos 2012-06-10 15:49:24 -07:00
parent d6aa2ef83e
commit f7a9fb526e
2 changed files with 8 additions and 4 deletions

View File

@ -317,7 +317,11 @@
}
type = opts.type, headers = opts.headers, upCallbacks = opts.upCallbacks, data = opts.data;
r = new XMLHttpRequest();
r.open(type || 'get', url, true);
if (data) {
type || (type = 'post');
}
type || (type = 'get');
r.open(type, url, true);
for (key in headers) {
val = headers[key];
r.setRequestHeader(key, val);
@ -2064,7 +2068,6 @@
};
opts = {
data: data,
type: 'POST',
upCallbacks: {
onload: function() {
return QR.status({

View File

@ -268,7 +268,9 @@ $.extend $,
ajax: (url, callbacks, opts={}) ->
{type, headers, upCallbacks, data} = opts
r = new XMLHttpRequest()
r.open type or 'get', url, true
type or= 'post' if data
type or= 'get'
r.open type, url, true
for key, val of headers
r.setRequestHeader key, val
$.extend r, callbacks
@ -1563,7 +1565,6 @@ QR =
textContent: 'Connection error, or you are banned.'
opts =
data: data
type: 'POST'
upCallbacks:
onload: ->
# Upload done, waiting for response.