会员
周边
众包
新闻
博问
闪存
赞助商
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
X龙@China .Net 'blog
需要的不仅仅是工作,而是通过努力得来的美好将来。
博客园
::
首页
::
新随笔
::
联系
::
订阅
::
管理
公告
js ajax类
Posted on
2009-04-26 18:32
X龙
阅读(
255
) 评论(
0
)
编辑
收藏
举报
Code
//
显示消息
function
showMsg(div, responseText)
{
document.getElementById(div).innerHTML
=
responseText;
}
//
生成post的query
function
generate_post_query(f)
{
var
q
=
''
;
for
(
var
i
=
0
; i
<
f.elements.length; i
++
)
{
if
(i
!=
0
); q
+=
'
&
'
;
q
+=
f.elements[i].name
+
'
=
'
+
f.elements[i].value;
}
return
q;
}
//
AJAX类
function
Ajax()
{
this
.xmlhttp
=
createXmlHttp();
function
createXmlHttp()
{
if
(window.XMLHttpRequest)
{
//
非IE
req
=
new
XMLHttpRequest();
}
else
if
(window.ActiveXObject)
{
//
IE
req
=
new
ActiveXObject(
"
Microsoft.XMLHTTP
"
);
}
return
req;
}
Ajax.prototype.ajaxGet
=
function
(url)
{
var
responseText
=
''
;
this
.xmlhttp.onreadystatechange
=
function
()
{
//
this指向触发事件的对象(即xmlhttp)
if
(
this
.readyState
==
4
)
{
if
(
this
.status
==
200
)
{
//
alert(this_obj.xmlhttp.getAllResponseHeaders());
responseText
=
this
.responseText;
}
else
{
alert(
'
There was a problem with the request. (
'
+
this
.status
+
'
)
'
);
}
}
}
this
.xmlhttp.open(
"
GET
"
, url,
true
);
this
.xmlhttp.setRequestHeader(
'
Content-Type
'
,
'
application/x-www-form-urlencoded
'
);
this
.xmlhttp.send(
null
);
return
responseText;
}
Ajax.prototype.ajaxPost
=
function
(url, query)
{
var
responseText
=
''
;
this
.xmlhttp.onreadystatechange
=
function
()
{
//
this指向触发事件的对象(即xmlhttp)
if
(
this
.readyState
==
4
)
{
if
(
this
.status
==
200
)
{
responseText
=
this
.responseText;
}
else
{
alert(
'
There was a problem with the request. (
'
+
this
.status
+
'
)
'
);
}
}
}
this
.xmlhttp.open(
'
POST
'
, url);
this
.xmlhttp.setRequestHeader(
'
Content-Type
'
,
'
application/x-www-form-urlencoded
'
);
this
.xmlhttp.send(query);
return
responseText;
}
}
X'L
会员力量,点亮园子希望
刷新页面
返回顶部
Powered by:
博客园
Copyright © 2024 X龙
Powered by .NET 8.0 on Kubernetes