1.客户端代码:(通过一个button触发)
  <script language="javascript" type="text/javascript">
// <!CDATA[
    var xmlHttpRequest;
    var xmlDoc; 
function Button1_onclick() 
{
     xmlDoc = new ActiveXObject('Microsoft.XMLDOM'); 
     xmlDoc.load("sql.xml"); 
     if(xmlDoc == null) 
   { 
   alert('您的浏览器不支持xml文件读取,于是本页面禁止您的操作,推荐使用IE5.0以上可以解决此问题!'); 
   } 
  xmlHttpRequest=new ActiveXObject("Msxml2.XMLHTTP"); 
  xmlHttpRequest.onreadystatechange=handleStateChange;
  xmlHttpRequest.open("POST", "http://localhost/test0304/default.aspx", true);
  xmlHttpRequest.setRequestHeader("Content-Type","text/xml");
  xmlHttpRequest.send(xmlDoc); 
}
function handleStateChange()
    {  
    var test=xmlHttpRequest.readyState;
     
       if(xmlHttpRequest.readyState==4)
       { 
            alert(xmlHttpRequest.status);
        if(xmlHttpRequest.status==200)
         {
        }
       }
    }
// ]]>
</script>
2.服务器端代码:(通过iis发布,虚拟路径为http://localhost/test0304/default.aspx)
 protected void Page_Load(object sender, EventArgs e)
    {
      if (Request.InputStream.Length != 0)
     {
     this.Request.Files[0].SaveAs("c:\\data.xml");
      }
      else
          Response.Write("<script>alert('验证码错误')</script>");
    }
点击客户端的button后,淡出提示框,显示发送成功;
然后通过IE打开http://localhost/test0304/default.aspx,结果弹出提示框验证码错误,而没有生成data.xml,请大家指点.

解决方案 »

  1.   

    直接访问是Get方式 inputstream的长度肯定为0
      

  2.   

    AJAX的POST方式貌似要设置个什么请求的属性,好像是是application/x-www-form-urlencoded(我想象着乱写的),反正就这个东西
      

  3.   

    请教慕白兄,我在服务器端怎么获得客户端post的数据?
      

  4.   

    用Request.InputStream是可以的,但是必须是post,直接用url访问是不行的.
      

  5.   

    二楼大哥,我将xmlHttpRequest.setRequestHeader("Content-Type","text/xml")换成了 
    xmlHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded")还是不行啊
    继续等待.
      

  6.   

    this.Request.SaveAs("c:\\data.xml",false);另:你的dom load目录不明确
    try:xmlHttpRequest.send("<?xml version=\"1.0\" standalone=\"yes\" ?><a>2</a>"); 
      

  7.   

    慕白兄
    哦,我放了一个xml放在项目里面在,路径没有问题
    另外打开http://localhost/test0304/default.aspx程序是运行的这一句
    else 
              Response.Write(" <script>alert('验证码错误') </script>"); 
    和刚开始一样.
    继续等待...
      

  8.   

    谢谢慕白兄.
    的确是你说的发送的xml文件的问题