Yii Framework Forum: Link To Controller Influences Ajax-Url In View - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Link To Controller Influences Ajax-Url In View Rate Topic: -----

#1 User is offline   Gerhard Liebenberg 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 340
  • Joined: 07-January 12
  • Location:Stillbay - Western Cape - South Africa

Posted 29 January 2013 - 01:09 AM

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
0

#2 User is offline   Gerhard Liebenberg 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 340
  • Joined: 07-January 12
  • Location:Stillbay - Western Cape - South Africa

Posted 29 January 2013 - 11:54 AM

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
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users