ajax tweaks
This commit is contained in:
parent
bf0326f38c
commit
5e464b288f
@ -327,19 +327,18 @@
|
|||||||
return $.rm(script);
|
return $.rm(script);
|
||||||
},
|
},
|
||||||
ajax: function(url, cb, opts) {
|
ajax: function(url, cb, opts) {
|
||||||
var key, r, val, _ref;
|
var event, headers, key, r, type, val;
|
||||||
opts.type || (opts.type = 'get');
|
if (opts == null) opts = {};
|
||||||
opts.event || (opts.event = 'onload');
|
type = opts.type, event = opts.event, headers = opts.headers;
|
||||||
|
type || (type = 'get');
|
||||||
|
event || (event = 'onload');
|
||||||
r = new XMLHttpRequest();
|
r = new XMLHttpRequest();
|
||||||
if (opts.headers) {
|
for (key in headers) {
|
||||||
_ref = opts.headers;
|
val = headers[key];
|
||||||
for (key in _ref) {
|
r.setRequestHeader(key, val);
|
||||||
val = _ref[key];
|
|
||||||
r.setRequestHeader(key, val);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
r[opts.event] = cb;
|
r[event] = cb;
|
||||||
r.open(opts.type, url, true);
|
r.open(type, url, true);
|
||||||
r.send();
|
r.send();
|
||||||
return r;
|
return r;
|
||||||
},
|
},
|
||||||
|
|||||||
@ -231,15 +231,15 @@ $.extend $,
|
|||||||
textContent: "(#{code})()"
|
textContent: "(#{code})()"
|
||||||
$.add d.head, script
|
$.add d.head, script
|
||||||
$.rm script
|
$.rm script
|
||||||
ajax: (url, cb, opts) ->
|
ajax: (url, cb, opts={}) ->
|
||||||
opts.type or= 'get'
|
{type, event, headers} = opts
|
||||||
opts.event or= 'onload'
|
type or= 'get'
|
||||||
|
event or= 'onload'
|
||||||
r = new XMLHttpRequest()
|
r = new XMLHttpRequest()
|
||||||
if opts.headers
|
for key, val of headers
|
||||||
for key, val of opts.headers
|
r.setRequestHeader key, val
|
||||||
r.setRequestHeader key, val
|
r[event] = cb
|
||||||
r[opts.event] = cb
|
r.open type, url, true
|
||||||
r.open opts.type, url, true
|
|
||||||
r.send()
|
r.send()
|
||||||
r
|
r
|
||||||
cache: (url, cb) ->
|
cache: (url, cb) ->
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user