代码之家  ›  专栏  ›  技术社区  ›  Anil Namde

帮助使用yui将XML字符串/文档作为Ajax请求提交到后台页面

  •  0
  • Anil Namde  · 技术社区  · 15 年前

    我想在aspx页面上创建XML字符串,然后使用yui-ajax请求将此请求提交到另一个aspx页面进行处理。所以 1。通过像我们在Ajax响应上那样设置一些Ajax请求配置,这是可能的吗? 2。怎么做?

    2 回复  |  直到 13 年前
        1
  •  1
  •   Roland Bouman    15 年前

    是,使用yahoo.util.connect( http://developer.yahoo.com/yui/docs/YAHOO.util.Connect.html )

    代码如下:

    var myXmlString = "<?xml version='1.0'?>"+
                      ...
    ;
    var conn = YAHOO.util.Connect.asyncRequest ( 
        "POST", 
        "http://myhost/mypage.aspx", 
        {
            success: function(o) { 
                ...callback...
                // o.responseXML contains the response
            },
            error: function(o){
            }
        },
        myXmlString
    );
    

    有关详细信息,请参阅文档

        2
  •  0
  •   Anil Namde    15 年前

    使用以下代码段传递XML。它还可以用来传递JSON数据。 < BR> <代码> yahoo.util.connect.setDefaultPostHeader(false);
    yahoo.util.connect.initheader(“内容类型”,“application/xml;charset=utf-8”);
    var myxmlstring='测试数据';
    var conn=yahoo.util.connect.asyncRequest(
    “POST”,
    “backgroundpage.aspx”,

    成功:函数(o)
    div.innerhtml=“成功”+o.responsetext;
    },
    错误:函数(o)
    div.innerhtml=“错误”;

    },
    myxmlstring
    ); < /代码>

    div.innerhtml=“错误”;
    }
    }
    MyxMLSTART
    )(二)