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