1.js文件
1 function SendHttp(URL,XmlContent)
2 {
3 var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
4 xmlhttp.open("POST", URL, false);
5 xmlhttp.setRequestHeader("Content-Type","text/xml");
6
7 if(XmlContent.length==0)
8 {
9 xmlhttp.send("<?xml version=\"1.0\" encoding=\"utf-8\"?><root></root>");
10 }
11 else
12 {
13 xmlhttp.send(XmlContent);
14 }
15
16 var retValue = "";
17 if (xmlhttp.status != 200)
18 alert(xmlhttp.statusText);
19 else
20 {
21 retValue = xmlhttp.responseText;
22 }
23 return retValue;
24 }
25
2.使用方法2 {
3 var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
4 xmlhttp.open("POST", URL, false);
5 xmlhttp.setRequestHeader("Content-Type","text/xml");
6
7 if(XmlContent.length==0)
8 {
9 xmlhttp.send("<?xml version=\"1.0\" encoding=\"utf-8\"?><root></root>");
10 }
11 else
12 {
13 xmlhttp.send(XmlContent);
14 }
15
16 var retValue = "";
17 if (xmlhttp.status != 200)
18 alert(xmlhttp.statusText);
19 else
20 {
21 retValue = xmlhttp.responseText;
22 }
23 return retValue;
24 }
25
1>要先把js文件引用到页面里
2>用法如下
1 var strURL = "xxx.aspx?id=x";
2 var strXmlContent = "<?xml version=\"1.0\" encoding=\"utf-8\"?><root></root>";
3 var strRetValue = SendHttp(strURL , strXmlContent);
说明:xxx.aspx是一个页面文件,把里面的所有东西都给删除掉,除了第一行:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="xxx.aspx.cs" Inherits="xxx" %>
3.后台调用方法
1 protected void Page_Load(object sender, EventArgs e)
2 {
3 //url参数
4 string id = "";
5 if(Request.Qustring["id"]!=null)
6 {
7 id = Request.Qustring["id"].ToString();
8 }
9 //xml参数
10 XmlDocument xmldoc = new XmlDocument();
11 xmldoc.Load(Request.InputStream);
12 string xmlcontent = xmldoc.InnerXml;
13 Operate(id,xmlcontent);
14 }
15 public void Operate(string id,string xmlcontent)
16 {
//返回值
17 Response.Write("ID="+id+"xml="+xmlcontent);
18 }
2 {
3 //url参数
4 string id = "";
5 if(Request.Qustring["id"]!=null)
6 {
7 id = Request.Qustring["id"].ToString();
8 }
9 //xml参数
10 XmlDocument xmldoc = new XmlDocument();
11 xmldoc.Load(Request.InputStream);
12 string xmlcontent = xmldoc.InnerXml;
13 Operate(id,xmlcontent);
14 }
15 public void Operate(string id,string xmlcontent)
16 {
//返回值
17 Response.Write("ID="+id+"xml="+xmlcontent);
18 }
这种方法的缺点:
1.只能应用于IE浏览器中
2.可能会有其它错误.