Link To Controller Influences Ajax-Url In View

Hi guys

I have a link to my adminAction.

The adminAction renders the view, which also contains this piece of ajax code:


var request = $.ajax({ 

  url: "Admin",

  type: "GET",

  cache: false,

  data: {parentID : myPK},

  dataType: "html" 

});

However, the link to the adminAction, influences the url generated by the above ajax:

If the link to my adminAction is:


<a href="<?php echo Yii::app()->request->baseUrl; ?>/index.php/controller/admin">Roles</a>

then the Ajax-url is correct:


http://.../index.php/controller/Admin?parentID=47

But if the link to my adminAction is:


<?php echo CHtml::link('Roles',array('controller/admin')); ?>

then the Ajax-url does not contain the controller name, resulting in a 404 error:


http://.../index.php/Admin?parentID=47

Any ideas why this could be happening?

Thanx

OK I think I got it working now.

The problem seems to be CHtml::link and urlManager:

I have this line in my urlManager:


'<controller:\w+>' =>'<controller>/admin', // if no action is included, then

                                           // use actionAdmin

However, when the user clicks on the CHtml::link to go to actionAdmin, then the above line causes CHtml::link to NOT include the action’s name in the url in the browser’s address bar.

This seems to cause problems when Ajax has to use the url.

So, if you get Ajax 404 and ‘response failed’ errors, start by making sure that your url contains both controller and action names.

(I’m not an Ajax expert, so if this sounds like nonsense, please let me know.)

Thanx