responseXML vs. responseText

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • KAS
    New Member
    • Dec 2006
    • 1

    #1

    responseXML vs. responseText

    First of all, I am very much a newbie...

    From what I have read, it seems to me that both of these should be filled in all the time. The responseXML being a DOM representation and the responseText being a string representation of the response. Right? If so, then why do I sometimes have a responseText with no responseXML?

    A second part to that question is accessing the data in responseText. Here is what I have done. On the server side, I have this statement
    [PHP]<cotd chefs="<?=seria lize($randchefs )?>" /cotd>[/PHP]

    $randchefs is an array of 10 items each with 3 fields. As I understand XML, I cannot pass that as an array so I serialized it. Now in my javascript, I want to unserialize it. Here's my code...
    [PHP]$randchefs=unse rialize(req.res ponseText);[/PHP]

    I am using the responseText field because the data is not in the responseXML field. The above line of code does not seem to work and I do not understand why. I suspect I am missing some basic concept but after hours of googling, I still can't figure it out. Can someone help me?

    If it helps, here is the larger block of javascript

    [PHP]function getRandomChefs( ) {
    new Ajax.Request('/admin/services/rest/editorial/otd/chef/randchefs',
    {
    method: 'post',
    parameters: Form.serialize( 'addform'),
    onComplete: function(req) {
    $randchefs=unse rialize(req.res ponseText);
    console.log($ra ndchefs);

    }
    }
    );

    }[/PHP]
  • steven
    New Member
    • Sep 2006
    • 143

    #2
    Originally posted by KAS
    From what I have read, it seems to me that both of these should be filled in all the time. The responseXML being a DOM representation and the responseText being a string representation of the response. Right? If so, then why do I sometimes have a responseText with no responseXML?
    To my understanding, responseXML will only contain content when your server script responds with XML.

    I believe you would need to set the header content type as text/xml

    in your script. Then it should send any response with that content type.

    Perhaps this tutorial can help you.

    http://www-128.ibm.com/developerworks/web/library/wa-ajaxintro8.html

    Comment

    Working...