- var state = { xhr: new XMLHttpRequest(), url: this.expandURL(target), start: Date.now() },
- opt = Object.assign({}, options, state),
- content = null,
- contenttype = null,
- callback = this.handleReadyStateChange;
-
- return new Promise(function(resolveFn, rejectFn) {
- opt.xhr.onreadystatechange = callback.bind(opt, resolveFn, rejectFn);
- opt.method = String(opt.method || 'GET').toUpperCase();
-
- if ('query' in opt) {
- var q = (opt.query != null) ? Object.keys(opt.query).map(function(k) {
- if (opt.query[k] != null) {
- var v = (typeof(opt.query[k]) == 'object')
- ? JSON.stringify(opt.query[k])
- : String(opt.query[k]);
-
- return '%s=%s'.format(encodeURIComponent(k), encodeURIComponent(v));
- }
- else {
- return encodeURIComponent(k);
- }
- }).join('&') : '';
-
- if (q !== '') {
- switch (opt.method) {
- case 'GET':
- case 'HEAD':
- case 'OPTIONS':
- opt.url += ((/\?/).test(opt.url) ? '&' : '?') + q;
- break;
-
- default:
- if (content == null) {
- content = q;
- contenttype = 'application/x-www-form-urlencoded';
+ return Promise.resolve(target).then((function(url) {
+ var state = { xhr: new XMLHttpRequest(), url: this.expandURL(url), start: Date.now() },
+ opt = Object.assign({}, options, state),
+ content = null,
+ contenttype = null,
+ callback = this.handleReadyStateChange;
+
+ return new Promise(function(resolveFn, rejectFn) {
+ opt.xhr.onreadystatechange = callback.bind(opt, resolveFn, rejectFn);
+ opt.method = String(opt.method || 'GET').toUpperCase();
+
+ if ('query' in opt) {
+ var q = (opt.query != null) ? Object.keys(opt.query).map(function(k) {
+ if (opt.query[k] != null) {
+ var v = (typeof(opt.query[k]) == 'object')
+ ? JSON.stringify(opt.query[k])
+ : String(opt.query[k]);
+
+ return '%s=%s'.format(encodeURIComponent(k), encodeURIComponent(v));
+ }
+ else {
+ return encodeURIComponent(k);
+ }
+ }).join('&') : '';
+
+ if (q !== '') {
+ switch (opt.method) {
+ case 'GET':
+ case 'HEAD':
+ case 'OPTIONS':
+ opt.url += ((/\?/).test(opt.url) ? '&' : '?') + q;
+ break;
+
+ default:
+ if (content == null) {
+ content = q;
+ contenttype = 'application/x-www-form-urlencoded';
+ }