Skip to content

Commit 1163a43

Browse files
DmitryScalettaAlcaDesign
authored andcommitted
client: use xhr for api requests
1 parent b760444 commit 1163a43

File tree

1 file changed

+3
-18
lines changed

1 file changed

+3
-18
lines changed

lib/api.js

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ var api = function api(options, callback) {
3434
err => callback(err, response, null)
3535
);
3636
}
37-
// Inside an extension/ReactNative -> we cannot use jsonp!
38-
else if(_.isExtension() || _.isReactNative()) {
39-
var opts = _.merge({ url, method: "GET", headers: {} }, options);
37+
// Web application, extension, React Native etc.
38+
else {
39+
var opts = _.merge({ method: "GET", headers: {} }, options, { url });
4040
// prepare request
4141
var xhr = new XMLHttpRequest();
4242
xhr.open(opts.method, opts.url, true);
@@ -58,21 +58,6 @@ var api = function api(options, callback) {
5858
// submit
5959
xhr.send();
6060
}
61-
// Inside a web application, use jsonp..
62-
else {
63-
var script = document.createElement("script");
64-
// Callbacks must match the regex [a-zA-Z_$][\w$]*(\.[a-zA-Z_$][\w$]*)*
65-
var callbackName = `jsonp_callback_${Math.round(100000 * Math.random())}`;
66-
window[callbackName] = function(data) {
67-
delete window[callbackName];
68-
document.body.removeChild(script);
69-
callback(null, null, data);
70-
};
71-
72-
// Inject the script in the document..
73-
script.src = `${url}${url.includes("?") ? "&" : "?"}callback=${callbackName}`;
74-
document.body.appendChild(script);
75-
}
7661
}
7762

7863
module.exports = api;

0 commit comments

Comments
 (0)