Yii Framework Forum: Chtml::ajaxlink With Yii::app()->Request->Geturl(); - Yii Framework Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

Chtml::ajaxlink With Yii::app()->Request->Geturl(); CHtml::ajaxLink with Yii::app()->request->getUrl(); Rate Topic: ***** 2 Votes

#1 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 831
  • Joined: 20-April 11
  • Location:India

Posted 25 September 2012 - 05:05 AM

ajax inside an ajax updated region problem with multiple ajaxlinks and ajaxbuttons [solved]


i want to use CHtml::ajaxLink with Yii::app()->request->getUrl() as action + parameter, and want to pass another parameter too..

<?php echo CHtml::ajaxLink('All', Yii::app()->request->getUrl(),array('type' =>'GET','data' =>array( 'val' => 'All'),'update'=>'#student_panel_handler')); ?>


any solution?

now the link is working but not getting previous Yii::app()->request->getUrl() parameters. i want that too.
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#2 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 831
  • Joined: 20-April 11
  • Location:India

Posted 25 September 2012 - 05:58 AM

used another method like this

<?php echo CHtml::ajaxLink('All', Yii::app()->createUrl('/site/manage' ),array('data' =>array( 'name' =>  $_REQUEST['name'],'admissionnumber'=> $_REQUEST['admissionnumber'],'val' => 'All',),'dataType' => 'text','update'=>'#student_panel_handler')); ?> 


the $_REQUEST['name'] is displaying when echo that, but not passing to the action.
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#3 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 831
  • Joined: 20-April 11
  • Location:India

Posted 25 September 2012 - 08:04 AM

any solution?
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#4 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 25 September 2012 - 08:36 AM

<?php echo CHtml::ajaxLink('All', array('/site/manage' ,  'name' =>  $_REQUEST['name'],'admissionnumber'=> $_REQUEST['admissionnumber'],'val' => 'All'), 'dataType' => 'text','update'=>'#student_panel_handler')); ?> 

0

#5 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 831
  • Joined: 20-April 11
  • Location:India

Posted 25 September 2012 - 08:42 AM

View Postzaccaria, on 25 September 2012 - 08:36 AM, said:

<?php echo CHtml::ajaxLink('All', array('/site/manage' ,  'name' =>  $_REQUEST['name'],'admissionnumber'=> $_REQUEST['admissionnumber'],'val' => 'All'), 'dataType' => 'text','update'=>'#student_panel_handler')); ?> 




i think , some syntax error in this, zaccaria
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#6 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 831
  • Joined: 20-April 11
  • Location:India

Posted 25 September 2012 - 08:47 AM

this is also not working!!
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#7 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,005
  • Joined: 16-February 11
  • Location:Japan

Posted 25 September 2012 - 09:03 AM

Maybe you are updating other parts of the page by this ajaxLink, but not the link itself. So it will hold the same parameters as the ones that were initially rendered. :)

I would render some hidden elements in the part that is to be updated by ajax.
<div id="searchName" class="hidden"><?php echo $searchName; ?></div>

# I don't want to display the raw $_REQUEST values in the view. I think it's dangerous and you should not do that. At the very least you have to escape them.

And read the values of them when I call ajax link.
<?php
echo CHtml::ajaxLink('All',
    Yii::app()->createUrl('/site/manage' ),
    array(
        'data' => 'js:{ "searchName" : $("#searchName").html(), "val" : "All" }',
        'dataType' => 'text',
        'update'=>'#student_panel_handler'
    )
);
?> 

Not tested, and may contain syntax errors. Just a rough sketch.
0

#8 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 831
  • Joined: 20-April 11
  • Location:India

Posted 26 September 2012 - 01:46 AM

yes that is right...i want to use ajax call repeatdly....want to refresh the same again and again...

i got a solution from here here

http://www.yiiframew...e-ajax-request/


but when i am adding id to it, its not working..
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#9 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,005
  • Joined: 16-February 11
  • Location:Japan

Posted 26 September 2012 - 02:38 AM

Well, my suggestion was in the assumption that your ajaxLink is located outside the ajax updated part.
It will not work if it is inside the ajax updated part.
0

#10 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 831
  • Joined: 20-April 11
  • Location:India

Posted 26 September 2012 - 05:05 AM

yes it is inside

found the problem is
when we click on that link the previous link is working

is there any solution?


assume we have 6 different ajaxlinks, when we click on any one of this the same div is refreshing and echos new 6 ajaxlinks.. but when we click on that actually the previous link is working..
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#11 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 831
  • Joined: 20-April 11
  • Location:India

Posted 26 September 2012 - 05:16 AM

if(isset($_REQUEST['name']) and $_REQUEST['name']!=NULL)
{
echo CHtml::ajaxLink("name", Yii::app()->createUrl('/site/manage' ), array('type' =>'GET','data' =>array( 'name' => $name,'admissionnumber'=>'','Students[batch_id]'=>$bat ),'dataType' => 'text',  'update' =>'#student_panel_handler',array()));

}

if(isset($_REQUEST['admissionnumber']) and $_REQUEST['admissionnumber']!=NULL)
{
echo CHtml::ajaxLink("add.No", Yii::app()->createUrl('/site/manage' ), array('type' =>'GET','data' =>array( 'name' => $name,'admissionnumber'=>'','Students[batch_id]'=>$bat ),'dataType' => 'text',  'update' =>'#student_panel_handler',array()));

}

if(isset($_REQUEST['Students']['batch_id']) and $_REQUEST['Students']['batch_id']!=NULL)
{
echo CHtml::ajaxLink("Batch", Yii::app()->createUrl('/site/manage' ), array('type' =>'GET','data' =>array( 'name' => $name,'admissionnumber'=>'','Students[batch_id]'=>$bat ),'dataType' => 'text',  'update' =>'#student_panel_handler',array()));

}






<?php echo CHtml::ajaxLink('A', Yii::app()->createUrl('/site/manage' ),array('data' =>array('name' =>$name,'admissionnumber'=>$ad,'Students[batch_id]'=>$bat, 'val' => 'A'),'dataType' => 'text','update'=>'#student_panel_handler'),array()); 

<?php echo CHtml::ajaxLink('B', Yii::app()->createUrl('/site/manage' ),array('data' =>array('name' =>$name,'admissionnumber'=>$ad,'Students[batch_id]'=>$bat, 'val' => 'B'),'dataType' => 'text','update'=>'#student_panel_handler'),array()); 

<?php echo CHtml::ajaxLink('C', Yii::app()->createUrl('/site/manage' ),array('data' =>array('name' =>$name,'admissionnumber'=>$ad,'Students[batch_id]'=>$bat, 'val' => 'C'),'dataType' => 'text','update'=>'#student_panel_handler'),array()); 

<?php echo CHtml::ajaxLink('D', Yii::app()->createUrl('/site/manage' ),array('data' =>array('name' =>$name,'admissionnumber'=>$ad,'Students[batch_id]'=>$bat, 'val' => 'C'),'dataType' => 'text','update'=>'#student_panel_handler'),array()); 



the first 3 links are active only after some submit.
after that when we click on that "name" link the link "A" with previous values are working..

like that
when we click on that "add.No" link the link "B" with previous values are working..

when we click on that "Batch" link the link "C" with previous values are working..



this is the problem. the link shown is correct but working is previous one.
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#12 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 831
  • Joined: 20-April 11
  • Location:India

Posted 26 September 2012 - 06:23 AM

is there any solution using like

'beforeSend' => 'function(){document.body.innerHTML = "";}'

its not ok..like this anything?
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#13 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,005
  • Joined: 16-February 11
  • Location:Japan

Posted 26 September 2012 - 06:37 AM

Well, as a general rule, I will not use CHtml::ajaxSomething in the div which will be updated by ajax. In other word, I only render plain html code inside an ajax updated region. And I will attach an event handler using jQuery.on().

Something like the following:

<div id="ajax-updated-region">
<?php echo CHtml::link("name", array('my/route', 'xxx' => $xxx, 'yyy' => $yyy)); ?>
<?php echo CHtml::link("number", array('my/route', 'xxx' => $xxx, 'zzz' => $zzz)); ?>
</div>

<?php
Yii::app()->clientScript->registerScript('ajax-link-handler', "
$('body').on('click', '#ajax-updated-region a', function(event){
	$.ajax({
		'type':'get',
		'url':$(this).attr('href'),
		'dataType': 'html',
		'success':function(data){
			$('#ajax-updated-region').html(data);
		}
	});
	event.preventDefault();
});
");
?>


This jQuery.on() handler watches inside the region to catch the click event. But because it resides outside of the ajax updated region (it is attached to 'body'), it will not be damaged by the ajax updating.

Personally I believe this is the most clean way to handle an ajax inside an ajax updated region.
1

#14 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 831
  • Joined: 20-April 11
  • Location:India

Posted 26 September 2012 - 06:46 AM

thanks softark once again ..i will try it and return to u
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#15 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 831
  • Joined: 20-April 11
  • Location:India

Posted 26 September 2012 - 07:28 AM

sorry softark ..this also not working fine . not taking the event handler.. directly going to that link not ajax.
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#16 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 831
  • Joined: 20-April 11
  • Location:India

Posted 26 September 2012 - 07:38 AM

the page is render like this

$this->renderPartial('explorer',array(),false,true);


is that is the problem?
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#17 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,005
  • Joined: 16-February 11
  • Location:Japan

Posted 26 September 2012 - 07:47 AM

Would you please try just:
$this->renderPartial('explorer',array());

Both in the initial rendering of the page and in the ajax response.
And also check your javascript console if there's an error.
0

#18 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,005
  • Joined: 16-February 11
  • Location:Japan

Posted 26 September 2012 - 07:53 AM

Ah, if you do not render the ajax updated region for the first time (if you do not call renderPartial to render the partial view initially), then you have to register the javascript in your main view script.
0

#19 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 831
  • Joined: 20-April 11
  • Location:India

Posted 26 September 2012 - 08:02 AM

not working...

directly going to that link

and in console error showing

The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must to be declared in the document or in the transfer protocol.
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#20 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,005
  • Joined: 16-February 11
  • Location:Japan

Posted 26 September 2012 - 08:11 AM

Would you please post your code (preferably an abbreviated version)?
0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • 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