XML response from a controller

Hi all,

I’m facing a problem regarding XML response from a controller.

a view:

$(document).ready(function() {


url: “<?php echo $this->createUrl(‘test/load’)?>”,

dataType: ($.browser.msie) ? "text" : "xml",

success: function(data) {






a test controller:

public function actionLoad() {

header ("Content-Type:text/xml");

echo ‘<elements><element id = 20 /></elements>’;


Any help appreciated!



i know its not XML but for me i always achieve that kind of functionality this way:

This is some JavaScript that will expect a controller processed answer.

$.post('<?php echo CController::createUrl('/someController/someAction'); ?>', {'someData': someData}, 



                var user = $('div.user',$(data)).html();

                var id = $('div.id',$(user)).html();

                var name = $('div.name',$(user)).html();



This is the Controller that processes the request and gives the answer:

public function actionSomeAction() {

        $someData = $_POST['someData'];

        // now doing something with that...


     * echo this now:

     *   <div>

     *     <div class="user">

     *       <div>

     *         <div class="id">12</div><div class="name">Peter</div>

     *       </div>

     *     </div>

     *   </div>



its most important to enclose the data with a <div></div>

PS: not sure if this will work as it is, because i needed to remove a lot of redundant code for this example…

but i hope you see what it does anyways.


Thank you Nohero, but I need exactly XML