尝试MagicAjax,发现非常方便,但是不支持多线程异步通讯。
为此我又根据需要自己写了一个小Ajax,作为MagicAjax的补充。ie和ff上运行良好。
这其实是从去年的Flexible里面改的。
1
//
2
if
(window.ActiveXObject)STD
=
false
;
3
else
STD
=
true
;
4
//
5![ExpandedBlockStart.gif](https://civ3.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
function
Ajax(fun)
{
6
this.a=(STD)?(new XMLHttpRequest):(new ActiveXObject('Microsoft.XMLHTTP'));
7
var ajax=this;
8
var xmlhttp=this.a;
9
10![ExpandedSubBlockStart.gif](https://civ3.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
xmlhttp.onreadystatechange=function()
{
11
if(xmlhttp.readyState==4)
12
fun(ajax.rsp());
13
}
14
15![ExpandedSubBlockStart.gif](https://civ3.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
this.req=function(cmd,par)
{
16
xmlhttp.open("POST","MyAjax.asmx/"+cmd,true);
17
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
18
xmlhttp.send("par="+par);
19
}
20![ExpandedSubBlockStart.gif](https://civ3.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
this.rsp=function()
{
21
return (STD)?xmlhttp.responseXML.firstChild.textContent:xmlhttp.responseXML.text;
22
}
23
}
24
其中fun是回调函数,用来处理返回消息。
![None.gif](https://civ3.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![None.gif](https://civ3.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![None.gif](https://civ3.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![None.gif](https://civ3.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![ExpandedBlockStart.gif](https://civ3.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![ContractedBlock.gif](https://civ3.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
6
![InBlock.gif](https://civ3.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
7
![InBlock.gif](https://civ3.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
8
![InBlock.gif](https://civ3.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
9
![InBlock.gif](https://civ3.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
10
![ExpandedSubBlockStart.gif](https://civ3.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](https://civ3.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
11
![InBlock.gif](https://civ3.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
12
![InBlock.gif](https://civ3.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
13
![ExpandedSubBlockEnd.gif](https://civ3.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
14
![InBlock.gif](https://civ3.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
15
![ExpandedSubBlockStart.gif](https://civ3.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](https://civ3.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
16
![InBlock.gif](https://civ3.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
17
![InBlock.gif](https://civ3.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
18
![InBlock.gif](https://civ3.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
19
![ExpandedSubBlockEnd.gif](https://civ3.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
20
![ExpandedSubBlockStart.gif](https://civ3.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](https://civ3.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
21
![InBlock.gif](https://civ3.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
22
![ExpandedSubBlockEnd.gif](https://civ3.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
23
![ExpandedBlockEnd.gif](https://civ3.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
24
![None.gif](https://civ3.cnblogs.com/Images/OutliningIndicators/None.gif)
请求包括命令cmd和参数par
这个Ajax对象封装了一个成员xmlhttp
两个方法:
请求req和响应rsp
//
满足此处需要就行了,以后再根据不同的需要扩展。