zoukankan      html  css  js  c++  java
  • 使用jquery的ajax功能post数据

     $.ajax({      

             type: "post",      

             url: "Ajax.ashx",      

             data: { id: "1",name:"mzl",xml:“<root><order><id>111</id><name>mazhlo</name></order></root>” },      //注意格式

             success: function (html) {                  

           alert("1:" + html);  //注意不是html.responseText

                 }        

       });

    在ajax.ashx中可以如下方式访问:

            public void ProcessRequest(HttpContext context)      

       {          

         context.Response.ContentType = "text/plain";

        try

                {

                    System.Xml.XmlDocument doc = new XmlDocument();

           string xml=context.Request.Form["xml"];    //注意后台访问格式

                    doc.LoadXml(xml);

                    XmlNodeList nodes = doc.SelectNodes("/root/order"); //或者 XmlNodeList nodes = doc.DocumentElement.SelectNodes("./order");

                   foreach (XmlNode node in nodes)

                    {

                        context.Response.Write("order:\n");

                        XmlNode id = node.SelectSingleNode("./id");

                        context.Response.Write("id:" + id.InnerText+"\n"); 

                       XmlNode name = node.SelectSingleNode("./name"); 

                       context.Response.Write("name:" + name.InnerText + "\n"); 

                   } 

                }

                catch (Exception ex) 

               { 

                   context.Response.Write(ex.Message);

                } 

           }

  • 相关阅读:
    spring cloud学习(五) 配置中心
    spring cloud学习(四) 动态路由
    spring cloud学习(三) 断路器
    spring cloud学习(二) 调用服务
    spring cloud学习(一) 服务注册
    spring boot实现异步调用
    openlayers 5.3记录
    asp.net core3.1 实战开发(EF+Mysql 从数据库生成实体类到项目)
    asp.net core3.1 实战开发(EF+Sqlserver 从数据库生成实体类到项目)
    Jexus独立版(专业版)的安装
  • 原文地址:https://www.cnblogs.com/mazhlo/p/2004098.html
Copyright © 2011-2022 走看看