XML response from a controller

Hi all,

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

a view:

$(document).ready(function() {

$.ajax({

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

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

success: function(data) {

 &#036;(data).find('element').each(function(){


    alert(&#036;(this).attr('id'));


 });


});

});

a test controller:

public function actionLoad() {

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

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

}

Any help appreciated!

Thanks

Hi,

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}, 

        function(data){

            

                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.

hth

Thank you Nohero, but I need exactly XML