mirror of
https://github.com/JamesonHuang/OpenWrt_Luci_Lua.git
synced 2024-11-27 23:40:10 +00:00
130 lines
3.4 KiB
HTML
130 lines
3.4 KiB
HTML
|
<!DOCTYPE html>
|
||
|
<html lang="zh-CN">
|
||
|
<head>
|
||
|
<meta charset="UTF-8" />
|
||
|
</head>
|
||
|
<body>
|
||
|
<script>
|
||
|
var outerPagePtr;
|
||
|
var outerPageOrigin;
|
||
|
var ALLOWORIGIN = "http://miwifi.com";
|
||
|
|
||
|
var EventUtil = {
|
||
|
addHandler: function (element, type, handler) {
|
||
|
if (element.addEventListener) {
|
||
|
element.addEventListener(type, handler, false);
|
||
|
} else if (element.attachEvent) {
|
||
|
element.attachEvent("on" + type, handler);
|
||
|
} else {
|
||
|
element["on" + type] = handler;
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
EventUtil.addHandler(window, "message", function (event) {
|
||
|
var url = event.data;
|
||
|
outerPagePtr = event.source;
|
||
|
outerPageOrigin = event.origin;
|
||
|
if (outerPageOrigin == ALLOWORIGIN) {
|
||
|
processMessage(url, function(rsp){
|
||
|
outerPagePtr.postMessage(rsp, outerPageOrigin);
|
||
|
});
|
||
|
}
|
||
|
});
|
||
|
|
||
|
var Factory = {
|
||
|
create: function() {
|
||
|
return function() { this.init.apply(this, arguments); }
|
||
|
}
|
||
|
}
|
||
|
|
||
|
var Ajax = Factory.create();
|
||
|
|
||
|
Ajax.prototype = {
|
||
|
init: function (successCallback, failureCallback) {
|
||
|
this.xhr = this.createXMLHttpRequest();
|
||
|
var xhrTemp = this.xhr;
|
||
|
var successFunc = null;
|
||
|
var failFunc = null;
|
||
|
|
||
|
if (successCallback != null && typeof successCallback == "function") {
|
||
|
successFunc = successCallback;
|
||
|
}
|
||
|
|
||
|
if (failureCallback != null && typeof failureCallback == "function") {
|
||
|
failFunc = failureCallback;
|
||
|
}
|
||
|
|
||
|
this.xhr.onreadystatechange = function () {
|
||
|
if (xhrTemp.readyState == 4) {
|
||
|
if (xhrTemp.status == 200) {
|
||
|
if (successFunc != null) {
|
||
|
successFunc(xhrTemp.responseText, xhrTemp.responseXML);
|
||
|
}
|
||
|
}else {
|
||
|
if (failFunc != null) {
|
||
|
var rsp = '{code: -1, msg:'+ xhrTemp.status + '}';
|
||
|
failFunc(rsp);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
get: function (url, async) {
|
||
|
this.xhr.open("GET", url, async);
|
||
|
this.xhr.send();
|
||
|
},
|
||
|
createXMLHttpRequest: function () {
|
||
|
if (window.XMLHttpRequest) {
|
||
|
return new XMLHttpRequest();
|
||
|
}
|
||
|
else {
|
||
|
return new ActiveXObject("Microsoft.XMLHTTP");
|
||
|
}
|
||
|
|
||
|
throw new Error("Ajax is not supported by the browser!");
|
||
|
},
|
||
|
post: function (url, data, async) {
|
||
|
this.xhr.open("POST", url, async);
|
||
|
this.xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
||
|
this.xhr.send(data);
|
||
|
},
|
||
|
random: function (length) {
|
||
|
var array = new Array("0", "1", "2", "3", "5", "6", "7", "8", "9");
|
||
|
var len = parseInt(length);
|
||
|
var key = "";
|
||
|
|
||
|
for (var i = 0; i < len; i++) {
|
||
|
key += Math.floor(Math.random() * 10);
|
||
|
}
|
||
|
|
||
|
return key;
|
||
|
}
|
||
|
};
|
||
|
Ajax.get = function(url, success, fail){
|
||
|
var ajax = new Ajax(success,fail),
|
||
|
hasQuery = url.indexOf('?') > 0,
|
||
|
random = hasQuery ? '&t=' + ajax.random(10) : '?t=' + ajax.random(10),
|
||
|
_url = url + random;
|
||
|
ajax.get(_url, true);
|
||
|
};
|
||
|
Ajax.post = function(url, data, success, fail){
|
||
|
var ajax = new Ajax(success,fail);
|
||
|
ajax.post(url, data, true);
|
||
|
};
|
||
|
var processMessage = function(url, success){
|
||
|
var hasQuery = url.indexOf('?') > 0,
|
||
|
urlArr,
|
||
|
baseURL = url,
|
||
|
params = '';
|
||
|
if (hasQuery) {
|
||
|
urlArr = url.split('?');
|
||
|
baseURL = urlArr[0];
|
||
|
params = urlArr[1];
|
||
|
}
|
||
|
Ajax.post(baseURL, params, success, success);
|
||
|
//Ajax.get(url, success, success);
|
||
|
}
|
||
|
</script>
|
||
|
</body>
|
||
|
</html>
|