刚接触不久!   在C#中可把XML可看做表.

解决方案 »

  1.   

    还有就是对XML字段的附值是不是跟WEB的形式一样的呢?
      

  2.   

    这个跟c#无头,这段代码是写在aspx中的.脚本是客户端的vbscript与后台语言没有关系.
      

  3.   

    对,这个是包含在vbscript客户端的,但为什么用在.net上就不能执行到呢?
      

  4.   

    aspx页面中添加脚本
    function sendInfo()
    {
        var senddata = "<?xml version=""1.0"" encoding=""UTF-8""?>"+
                         "<er_trans version=""1.0"">"+
                         "<trans_type>generate_request</trans_type>"+
                         "<trans_field_block>"+
                         "<sp_id>"+$get('f1').value+"</sp_id>"+
                         "</trans_info>"+
                         "</trans_field_block>"+
                         "</er_trans>";
        var xmlHttp = new ActiveXObject("Msxml2.XmlHttp");
        xmlHttp.open("POST","demo.aspx",false);
        var result = xmlHttp.responseText;
        .....
    }demo.aspx.cs中进行请求的相应处理,可以使用如下的方法获取请求的初始xml参数
    private string GetPostData()
    {
        byte[] requestByte = Request.BinaryRead(Request.ContentLength);
        UTF8Encoding encode = new UTF8Encoding(true);
        return encode.GetString(requestByte);
    }
    最后返回结果,可以在处理的实际事件中加入
    Response.ContentType = "text/xml";
    Response.Write(方法返回的值);
      

  5.   

    谢谢楼上的各位,但我的问题是把XML中f1的值通过MyHttp.open "POST", "http://.....", False传到http://。那个后台去处理阿,好像你那个没有指定到http:// 只是传到demo。aspx页面上的?
      

  6.   

    我这里给出的demo.aspx只是一个例子而已,具体的你需要指向你实际做后台处理的页面中。
      

  7.   

    但我还是有个问题,我是在不知道后台的代码的,那个代码也不是用.net写的代码,我只知道把几个字段的值传到http://。 后台上执行。请问这段代码function sendInfo()
    {
        var senddata = "<?xml version=""1.0"" encoding=""UTF-8""?>"+
                         "<er_trans version=""1.0"">"+
                         "<trans_type>generate_request</trans_type>"+
                         "<trans_field_block>"+
                         "<sp_id>"+$get('f1').value+"</sp_id>"+
                         "</trans_info>"+
                         "</trans_field_block>"+
                         "</er_trans>";
        var xmlHttp = new ActiveXObject("Msxml2.XmlHttp");
        xmlHttp.open("POST","http://...",false);
        var result = xmlHttp.responseText;
        .....
    }能实现传递字段吗?
      

  8.   

    sorry,忘了一行语句
    xmlHttp.send( senddata );
    加到xmlHttp.open("POST","http://...",false);语句的下面
      

  9.   

    不好意思,近来忙毕业设计,没有到这里来结贴,刚我用了您的方法来调试了,现在我的那些值是直接传导http://  后台那里了,请问  我还需要在XXX.aspx.cs下用这些代码:
    private string GetPostData()
    {
        byte[] requestByte = Request.BinaryRead(Request.ContentLength);
        UTF8Encoding encode = new UTF8Encoding(true);
        return encode.GetString(requestByte);
    }我只是在前台用了function函数后,出现了缺少对象的错误。
    请问这是个什么错误呢?
      

  10.   

    如果后台http://...已经处理了你的请求,并已经返回了结果,你不需要再写额外的代码。
    关于function函数的错误,你可以设断点调试一下,看看是否有对象未定义或语法错误
      

  11.   

    如果你要发送xml格式的文件,可以这样
    a.aspx<%@ Page language="c#" Debug="true" %>
    <script>
    {
        var senddata = "<?xml version='1.0' encoding='UTF-8'?>"+
                         "<data>测试文字</data>"
        var xmlHttp = new ActiveXObject("Msxml2.XmlHttp");
        xmlHttp.open("POST","b.aspx",false);
        xmlHttp.send(senddata)
        var result = xmlHttp.responseText;
        alert(result)
    }
    </script>b.aspx<%@ Page Language="C#" %>
    <%@ Import Namespace="System.Xml" %><script runat="server">  protected void Page_Load( object sender, EventArgs e )
      {
        XmlDocument doc = new XmlDocument();
        doc.Load(Request.InputStream);
       Response.Write(doc.OuterXml);
      }
    </script>
    注意你发送的数据必须符合xml格式
      

  12.   

    function sendInfo()
            {
        var senddata = "<?xml version='1.0' encoding='UTF-8'?>"+
              "<er_trans version='1.0'>"+
              "<trans_type>generate_request</trans_type>"+
              "<trans_field_block>"+
              "<sp_id>"+$get('TBsp_id').value+"</sp_id>"+
              "<sp_order_number>"+$get('TBsp_order_num').value+"</sp_order_number>"+
              "<business_code>"+$get('TBbuss_code').value+"</business_code>"+
              "<location_id>"+$get('TBlocation_id').value+"</location_id>"+
              "<phone>"+$get('TBphone').value+"</phone>"+ 
              "<trans_info>"+
              "<send_type>"+$get('TBsend_type').value+"</send_type>"+ 
              "<content>"+$get('TBcontent').value+"</content>"+
              "<notes>"+$get('TBnotes').value+"</notes>"+
              "<info_title>test</info_title>"+                
              "</trans_info>"+
              "</trans_field_block>"+
              "</er_trans>";
                var xmlHttp = new ActiveXObject("Msxml2.XmlHttp");
                xmlHttp.open("POST","http://.....",false);
                xmlHttp.send( senddata );
                var result = xmlHttp.responseText;
                response.write(result);
        
            }<input id="Submit1" type="submit" value="发 送" onclick="sendInfo()" />各位麻烦能不能看看呢,为什么老提示说缺少对象呢,我的写法错了没
      

  13.   

    各位麻烦能不能看看呢,为什么老提示说缺少对象呢,我的写法错了没
    ===============
    1。
    哪里缺少对象?2。
    response.write(result);
    ========
    response 是哪里来的?》》》alert(result);
      

  14.   

    提示这行缺少对象:"<er_trans version='1.0'>"+  除了alert(result);