这里写个使用XMLHttpRequest调用页面,post数据的js。
代码
1 var xhr=false;
2 if(window.XMLHttpRequest) {
3 xhr=new XMLHttpRequest();//IE7+,Firefox,Opera,Chorme,Safari
4 } else {
5 try {
6 xhr=new ActiveXObject("MSXML2.XMLHTTP");//IE6+
7 }catch(e){
8 try {
9 xhr=new ActiveXObject("Microsoft.XMLHTTP");//IE6也行
10 }catch(e){return null;}
11 }
12 }
13
14 str = "Id=" + document.getElementById("Id").value;
15 xhr.open("POST","http://XXX.XXX.XXX",false);
16 xhr.setRequestHeader("Content-Length",str.length);
17 xhr.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded");
18 xhr.setRequestHeader("HeaderInfo",document.getElementById("HeaderInfo").value);
19 xhr.send(str);
20 txt1.document.write(xhr.responseText);
21
2 if(window.XMLHttpRequest) {
3 xhr=new XMLHttpRequest();//IE7+,Firefox,Opera,Chorme,Safari
4 } else {
5 try {
6 xhr=new ActiveXObject("MSXML2.XMLHTTP");//IE6+
7 }catch(e){
8 try {
9 xhr=new ActiveXObject("Microsoft.XMLHTTP");//IE6也行
10 }catch(e){return null;}
11 }
12 }
13
14 str = "Id=" + document.getElementById("Id").value;
15 xhr.open("POST","http://XXX.XXX.XXX",false);
16 xhr.setRequestHeader("Content-Length",str.length);
17 xhr.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded");
18 xhr.setRequestHeader("HeaderInfo",document.getElementById("HeaderInfo").value);
19 xhr.send(str);
20 txt1.document.write(xhr.responseText);
21