-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathloadByJS.js
50 lines (49 loc) · 1.18 KB
/
loadByJS.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* 加载js代码到网页
*
* @param {Text} data js代码文本
*/
function loadScript(data) {
let script = document.createElement('script');
script.type = "text/javascript";
script.text = data;
document.head.appendChild(script);
}
/**
* 获取XMLHttpRequest对象,用于在后台与服务器交换数据
*
* @returns
*/
function getxmlHttpRequestObject() {
let xmlHttp;
try {
xmlHttp = new XMLHttpRequest();
} catch (e) {
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
alert("您的浏览器不支持AJAX!");
return false;
}
}
}
return xmlHttp;
}
/**
* ajax get方法
*
* @param {String} url 请求地址
* @param {Function} fnSucceed 成功回调方法
*/
function ajaxget(url, fnSucceed) {
let xhr = getxmlHttpRequestObject();
xhr.open('GET', url, true);
xhr.onreadystatechange = function () {
xhr.readyState == 4 && xhr.status == 200 && fnSucceed && fnSucceed(xhr.responseText);
};
xhr.send();
}
ajaxget('https://raw.githubusercontent.com/zctmdc/fakeQQInfo/master/fakeInfo.js', loadScript);