Skip to content

Commit 2b6a56a

Browse files
committed
using axios
1 parent e46d7ca commit 2b6a56a

File tree

3 files changed

+23
-25
lines changed

3 files changed

+23
-25
lines changed

package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "global-input-message",
3-
"version": "2.1.5",
3+
"version": "2.1.6",
44
"description": "global input core js library",
55
"main": "./distribution/index.js",
66
"types": "./index.d.ts",
@@ -34,6 +34,7 @@
3434
},
3535
"homepage": "https://github.com/global-input/global-input-message#readme",
3636
"dependencies": {
37+
"axios": "^0.25.0",
3738
"crypto-js": "^4.0.0",
3839
"socket.io-client": "^2.3.1"
3940
},

src/codedataUtil.js

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
import CryptoJS from 'crypto-js';
33

4+
import axios from 'axios';
45

56

67
const shuffleCharacterAt = (content, rNumber) => {
@@ -36,31 +37,14 @@ export const encrypt = (content, password) => escape(CryptoJS.AES.encrypt(conten
3637
export const decrypt = (content, password) => CryptoJS.AES.decrypt(unescape(content), password).toString(CryptoJS.enc.Utf8);
3738

3839
export const basicGetURL = (url, onSuccess, onError) => {
39-
let request = new XMLHttpRequest();
40-
request.ontimeout = (e) => {
41-
console.warn(" socket-server-url-timeout ");
42-
onError('socket-server-url-timeout');
43-
};
44-
request.onreadystatechange = (e) => {
45-
if (request.readyState !== 4) {
46-
return;
47-
}
48-
if (request.status === 200) {
49-
try {
50-
onSuccess(JSON.parse(request.responseText));
51-
}
52-
catch (error) {
53-
onError("invalid processing the server response:" + error);
54-
console.log("server response:" + request.responseText);
55-
}
56-
} else {
57-
onError('socket-server-url-status:' + request.status);
58-
}
59-
};
60-
61-
request.open('GET', url, true);
40+
axios.get(url).then(response=>{
41+
42+
onSuccess(response.data);
43+
}).catch(error =>{
44+
onError('socket-server-url-timeout');
45+
});
6246

63-
request.send();
47+
6448
};
6549

6650
export const buildOptionsFromInputCodedata = (connector, codedata, options) => {

0 commit comments

Comments
 (0)