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);

                } 

           }

  • 相关阅读:
    “5W1H”带你来学习JavaScript
    [windows+cocos2dx]文本类
    server后台TCP连接存活问题
    (七):处理MFC
    Servlet中的request对象、重定向和转发的差别(6)
    ORACLE 存储函数
    【@伏草惟存@】7年系列博文精选
    笔记14:Docker 部署Python项目
    笔记13:Python 和 Elasticsearch 构建简易搜索
    笔试12:Bootstrap知识
  • 原文地址:https://www.cnblogs.com/mazhlo/p/2004098.html
Copyright © 2011-2022 走看看