Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
mirrors
openwrt
luci
提交
b2b3b181
L
luci
项目概览
mirrors
/
openwrt
/
luci
大约 1 年 前同步成功
通知
43
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
luci
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b2b3b181
编写于
9月 26, 2011
作者:
J
Jo-Philipp Wich
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
themes/base: xhr.js: clean code style, implement XHR.get() and XHR.poll() convenience functions
上级
2829139f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
82 addition
and
41 deletion
+82
-41
themes/base/htdocs/luci-static/resources/xhr.js
themes/base/htdocs/luci-static/resources/xhr.js
+82
-41
未找到文件。
themes/base/htdocs/luci-static/resources/xhr.js
浏览文件 @
b2b3b181
...
...
@@ -7,10 +7,10 @@ XHR = function()
{
this
.
reinit
=
function
()
{
if
(
window
.
XMLHttpRequest
)
{
if
(
window
.
XMLHttpRequest
)
{
this
.
_xmlHttp
=
new
XMLHttpRequest
();
}
else
if
(
window
.
ActiveXObject
)
{
else
if
(
window
.
ActiveXObject
)
{
this
.
_xmlHttp
=
new
ActiveXObject
(
"
Microsoft.XMLHTTP
"
);
}
else
{
...
...
@@ -19,7 +19,10 @@ XHR = function()
}
this
.
busy
=
function
()
{
switch
(
this
.
_xmlHttp
.
readyState
)
if
(
!
this
.
_xmlHttp
)
return
false
;
switch
(
this
.
_xmlHttp
.
readyState
)
{
case
1
:
case
2
:
...
...
@@ -32,7 +35,7 @@ XHR = function()
}
this
.
abort
=
function
()
{
if
(
this
.
busy
()
)
if
(
this
.
busy
()
)
this
.
_xmlHttp
.
abort
();
}
...
...
@@ -41,23 +44,23 @@ XHR = function()
this
.
reinit
();
var
xhr
=
this
.
_xmlHttp
;
var
code
=
this
.
_encode
(
data
);
var
code
=
this
.
_encode
(
data
);
url
=
location
.
protocol
+
'
//
'
+
location
.
host
+
url
;
if
(
code
)
if
(
url
.
substr
(
url
.
length
-
1
,
1
)
==
'
&
'
)
if
(
code
)
if
(
url
.
substr
(
url
.
length
-
1
,
1
)
==
'
&
'
)
url
+=
code
;
else
url
+=
'
?
'
+
code
;
xhr
.
open
(
'
GET
'
,
url
,
true
);
xhr
.
open
(
'
GET
'
,
url
,
true
);
xhr
.
onreadystatechange
=
function
()
{
if
(
xhr
.
readyState
==
4
)
{
if
(
xhr
.
readyState
==
4
)
{
var
json
=
null
;
if
(
xhr
.
getResponseHeader
(
"
Content-Type
"
)
==
"
application/json
"
)
{
if
(
xhr
.
getResponseHeader
(
"
Content-Type
"
)
==
"
application/json
"
)
{
try
{
json
=
eval
(
'
(
'
+
xhr
.
responseText
+
'
)
'
);
}
...
...
@@ -66,11 +69,11 @@ XHR = function()
}
}
callback
(
xhr
,
json
);
callback
(
xhr
,
json
);
}
}
xhr
.
send
(
null
);
xhr
.
send
(
null
);
}
this
.
post
=
function
(
url
,
data
,
callback
)
...
...
@@ -78,19 +81,19 @@ XHR = function()
this
.
reinit
();
var
xhr
=
this
.
_xmlHttp
;
var
code
=
this
.
_encode
(
data
);
var
code
=
this
.
_encode
(
data
);
xhr
.
onreadystatechange
=
function
()
{
if
(
xhr
.
readyState
==
4
)
callback
(
xhr
);
if
(
xhr
.
readyState
==
4
)
callback
(
xhr
);
}
xhr
.
open
(
'
POST
'
,
url
,
true
);
xhr
.
setRequestHeader
(
'
Content-type
'
,
'
application/x-www-form-urlencoded
'
);
xhr
.
setRequestHeader
(
'
Content-length
'
,
code
.
length
);
xhr
.
setRequestHeader
(
'
Connection
'
,
'
close
'
);
xhr
.
send
(
code
);
xhr
.
open
(
'
POST
'
,
url
,
true
);
xhr
.
setRequestHeader
(
'
Content-type
'
,
'
application/x-www-form-urlencoded
'
);
xhr
.
setRequestHeader
(
'
Content-length
'
,
code
.
length
);
xhr
.
setRequestHeader
(
'
Connection
'
,
'
close
'
);
xhr
.
send
(
code
);
}
this
.
cancel
=
function
()
...
...
@@ -103,41 +106,41 @@ XHR = function()
{
var
code
=
''
;
for
(
var
i
=
0
;
i
<
form
.
elements
.
length
;
i
++
)
for
(
var
i
=
0
;
i
<
form
.
elements
.
length
;
i
++
)
{
var
e
=
form
.
elements
[
i
];
if
(
e
.
options
)
if
(
e
.
options
)
{
code
+=
(
code
?
'
&
'
:
''
)
+
code
+=
(
code
?
'
&
'
:
''
)
+
form
.
elements
[
i
].
name
+
'
=
'
+
encodeURIComponent
(
e
.
options
[
e
.
selectedIndex
].
value
);
}
else
if
(
e
.
length
)
else
if
(
e
.
length
)
{
for
(
var
j
=
0
;
j
<
e
.
length
;
j
++
)
if
(
e
[
j
].
name
)
{
code
+=
(
code
?
'
&
'
:
''
)
+
e
[
j
].
name
+
'
=
'
+
encodeURIComponent
(
e
[
j
].
value
);
for
(
var
j
=
0
;
j
<
e
.
length
;
j
++
)
if
(
e
[
j
].
name
)
{
code
+=
(
code
?
'
&
'
:
''
)
+
e
[
j
].
name
+
'
=
'
+
encodeURIComponent
(
e
[
j
].
value
);
}
}
else
{
code
+=
(
code
?
'
&
'
:
''
)
+
e
.
name
+
'
=
'
+
encodeURIComponent
(
e
.
value
);
code
+=
(
code
?
'
&
'
:
''
)
+
e
.
name
+
'
=
'
+
encodeURIComponent
(
e
.
value
);
}
}
if
(
typeof
extra_values
==
'
object
'
)
for
(
var
key
in
extra_values
)
code
+=
(
code
?
'
&
'
:
''
)
+
key
+
'
=
'
+
encodeURIComponent
(
extra_values
[
key
]
);
if
(
typeof
extra_values
==
'
object
'
)
for
(
var
key
in
extra_values
)
code
+=
(
code
?
'
&
'
:
''
)
+
key
+
'
=
'
+
encodeURIComponent
(
extra_values
[
key
]
);
return
(
(
form
.
method
==
'
get
'
)
?
this
.
get
(
form
.
getAttribute
(
'
action
'
),
code
,
callback
)
:
this
.
post
(
form
.
getAttribute
(
'
action
'
),
code
,
callback
)
(
form
.
method
==
'
get
'
)
?
this
.
get
(
form
.
getAttribute
(
'
action
'
),
code
,
callback
)
:
this
.
post
(
form
.
getAttribute
(
'
action
'
),
code
,
callback
)
);
}
...
...
@@ -146,14 +149,14 @@ XHR = function()
obj
=
obj
?
obj
:
{
};
obj
[
'
_
'
]
=
Math
.
random
();
if
(
typeof
obj
==
'
object
'
)
if
(
typeof
obj
==
'
object
'
)
{
var
code
=
''
;
var
self
=
this
;
for
(
var
k
in
obj
)
code
+=
(
code
?
'
&
'
:
''
)
+
k
+
'
=
'
+
encodeURIComponent
(
obj
[
k
]
);
for
(
var
k
in
obj
)
code
+=
(
code
?
'
&
'
:
''
)
+
k
+
'
=
'
+
encodeURIComponent
(
obj
[
k
]
);
return
code
;
}
...
...
@@ -161,3 +164,41 @@ XHR = function()
return
obj
;
}
}
XHR
.
get
=
function
(
url
,
data
,
callback
)
{
(
new
XHR
()).
get
(
url
,
data
,
callback
);
}
XHR
.
poll
=
function
(
interval
,
url
,
data
,
callback
)
{
if
(
isNaN
(
interval
)
||
interval
<=
1
)
interval
=
5
;
if
(
!
XHR
.
_q
)
{
XHR
.
_t
=
0
;
XHR
.
_q
=
[
];
}
XHR
.
_q
.
push
({
interval
:
interval
,
callback
:
callback
,
url
:
url
,
data
:
data
,
xhr
:
new
XHR
()
});
if
(
!
XHR
.
_i
)
{
XHR
.
_i
=
window
.
setInterval
(
function
()
{
for
(
var
i
=
0
,
e
=
XHR
.
_q
[
0
];
i
<
XHR
.
_q
.
length
;
e
=
XHR
.
_q
[
++
i
])
{
if
(
!
(
XHR
.
_t
%
e
.
interval
)
&&
!
e
.
xhr
.
busy
())
e
.
xhr
.
get
(
e
.
url
,
e
.
data
,
e
.
callback
);
}
XHR
.
_t
++
;
},
1000
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录