Saturday, March 24, 2012

asp.net 1.1 ajax and xml

I'm trying to implement ajax on some of my forms by having an aspx page write out xml. I'm building the xml using a string builder and useing response.contentType = "text/xml" followed by response.write at the end. If I just display the page, it renders it as xml with all the right nodes and values which is cool, but when I call xmlDoc = xmlHttp.responseXML, I'm not getting any childnodes.

The same code works if I call an xml file as the src of the ajax call.

This is my first real crack at implementing this so if anyone has any ideas, I'm open. If I'm way off, let me know.

Thanks

Dave

I wound up getting this to work by adding ContentType="text/xml" to the page directive of my xml producing aspx page.

Here's the code that rendered the xml.

Public Sub GetResponse() Response.ContentType ="text/xml"Dim strVars()As String = {"one","two","three","four","five","six","seven","eight","nine","ten"}Dim strItemVals()As String Dim sbAs New StringBuilderDim counterAs Integer = 0Dim maxAs Integer = 10Dim loXmlAs New XmlTextWriter(Response.OutputStream, System.Text.Encoding.UTF8) loXml.WriteStartDocument() loXml.WriteStartElement("Response")For Each strAs String In strVarsIf counter < maxThen'Write Code via xml loXml.WriteStartElement(str)loXml.WriteString(str &" - Content") loXml.WriteEndElement() counter += 1Else Exit For End If Next loXml.WriteEndElement() loXml.WriteEndDocument() loXml.Close()End Sub

No comments:

Post a Comment