views:

108

answers:

2

I would like to create the XML string on the the aspx page and then submit this request using the YUI ajax request to another aspx page for the processiong. So 1. is this possible by setting some of the ajax requests configurations like we do on ajax response ? 2. How it can be done ?

+1  A: 

Yes, use YAHOO.util.Connect (http://developer.yahoo.com/yui/docs/YAHOO.util.Connect.html)

Code would go like:

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

See the docs for detailed infop

Roland Bouman
This means that while using YUI we do not have to set/specify any header for request content type explicitly ? like following,setHeader("content-type", "text/xml");
Anil Namde
I am sure you can set that. check the link and read.
Roland Bouman
A: 

xml is passed using following code snippet. It can also be used to pass the JSON data.
YAHOO.util.Connect.setDefaultPostHeader(false);
YAHOO.util.Connect.initHeader("Content-Type", "application/xml; charset=utf-8");
var myXmlString = 'TEST DATA';
var conn = YAHOO.util.Connect.asyncRequest (
"POST",
"BackgroundPage.aspx",
{
success: function(o) {
div.innerHTML = "Success" + o.responseText;
},
error: function(o){
div.innerHTML = "Error";
}
},
myXmlString
);

Anil Namde