This is my controller which (attempts to) create the xml doc from the
database:

@expose()
def getDivisions(self, segmentid, *args, **kw):
    def genAddElement( division ):
        return  """ <DIVISION>
                      <ID>%d</ID>
                      <NAME>'%s'</NAME>
                      <SEGMENTID>%d</SEGMENTID>
                    </DIVISION> """ % ( division.divisionid, division.name,
division.segmentid )

    divisions =
DBSession.query(Division).filter(Division.segmentid==int(segmentid)).order_by(Division.name).all()
    xmlElements = map( genAddElement, divisions )
    xmlStr = string.join( xmlElements, '\n' )
    xmlDoc = """ <?xml version='1.0' encoding='ISO-8859-1'?>
                 <DIVISIONS>
                     %s
                 </DIVISIONS> """ % (xmlStr)
    return xmlDoc
My javascript goes something like this:

function updateDivisions()
{
    var XMLHttpRequestObject = false;
    if (window.XMLHttpRequest)
    {
        XMLHttpRequestObject = new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    {
        XMLHttpRequestObject = new ActiveXObject('Microsoft.XMLHTTP');
    }
    if(XMLHttpRequestObject)
    {
        var segCtrl = document.getElementById('segment');
        var segVal = segmentCtrl.options[segmentCtrl.selectedIndex].value;
        XMLHttpRequestObject.onreadystatechange = function()
        {
            if (XMLHttpRequestObject.readyState == 4)
            {
                if (XMLHttpRequestObject.status == 200)
                {
                    xmlDoc = XMLHttpRequestObject.responseXML;
                }
            }
        }
        XMLHttpRequestObject.open('GET', "${tg.url('/sponsor/getDivisions/"
+ segVal + "')}");
        XMLHttpRequestObject.send(null);
    }
}
The XMLHttpRequestObject.status is returning 500 instead of 200.
 I think it has something to do with the way I'm creating the xml doc. Is
there another way?

Thanks.

On Wed, Jul 14, 2010 at 8:59 AM, vince spicer <[email protected]> wrote:

> Michael,
>
> you can use any controller and expose a template renders xml
>
> What kind of errors are you seeing in the server log?
>
>
>
>  On Tue, Jul 13, 2010 at 4:53 PM, Michael Pearce <[email protected]>wrote:
>
>>  I'm trying to use AJAX to return XML from the server to my web page.
>> Whilst I can get a text response from my Python controller script, I'm
>> having problems returning XML. When I check XMLHttpRequestObject.status I
>> always get 500 instead of 200. It seems my problem is related to the XML
>> format, so I guess the question is how to create an XML response in my
>> Python controller which will be called by AJAX code in my web page. Does
>> anyone have an example they could share.
>>
>> Thanks, Michael
>>
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "TurboGears" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected]<turbogears%[email protected]>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/turbogears?hl=en.
>>
>
>   --
> You received this message because you are subscribed to the Google Groups
> "TurboGears" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<turbogears%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/turbogears?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en.

Reply via email to