Yii Framework Forum: ajaxLink $ajaxOptions 'update' parent window? - Yii Framework Forum

Jump to content

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

ajaxLink $ajaxOptions 'update' parent window? Rate Topic: -----

#1 User is offline   koz 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 35
  • Joined: 23-June 10

Posted 08 July 2010 - 05:20 PM

How do i specify the parent window on 'update' ajaxOption ???

echo CHtml::ajaxLink(
                     'Delete from project',
                      array('link/DelFromProject'),
                      array(
                            'update' => '#index',
                            'type'=>'POST',
                            'data'=>array( 
                                         'id_link'=>CHtml::encode($data->id_link),
                                         'id_project'=>CHtml::encode($_REQUEST['id_project'])
                                         ) 
                            )
                     );



0

#2 User is offline   zaccaria 

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

Posted 09 July 2010 - 08:50 AM

When you use ajax links like that you have to create a div and replace his content.

This is the tipical scenario:

In the view:
<div id="index">
    <?php $this->renderPartial('_subview');?>
</div>


The ajax link:
<?php echo CHtml::ajaxLink(
   [...]
   array(
      'update' => '#index',
   )
);?>



And the controller will do a render partial on the subview, not on the whole view.

If you have to replace the whole view you can create the div in layout/main around $content

<div id="difForAjaxReplaceOfTheWholeView">
    <?php echo $content?>
</div>


0

#3 User is offline   koz 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 35
  • Joined: 23-June 10

Posted 09 July 2010 - 10:27 AM

View Postzaccaria, on 09 July 2010 - 08:50 AM, said:

When you use ajax links like that you have to create a div and replace his content.

This is the tipical scenario:

In the view:
<div id="index">
    <?php $this->renderPartial('_subview');?>
</div>


The ajax link:
<?php echo CHtml::ajaxLink(
   [...]
   array(
      'update' => '#index',
   )
);?>



And the controller will do a render partial on the subview, not on the whole view.

If you have to replace the whole view you can create the div in layout/main around $content

<div id="difForAjaxReplaceOfTheWholeView">
    <?php echo $content?>
</div>




Yes i understand that but i got two problems... first is i want to update the window.parent.document because i'm opening a lightbox with iframe and when i click a ajaxlink inside that iframe i want to update content of parent window.

I know jQuery parameter 'success' can do that like this:
'success' => 'function(data) 
{
    $("#teste", window.parent.document).html("File '.$id_file.' added with success to project '.$id_project.'"); 
    $("#index").html(data);
}'

But i want this on 'update' or 'replace' parameters...

Second problem is that on the parent window i got the list of Files added to that project. All File got an ajax link to delete the file from the project... the problem is when i 1 link is ok... when i click the second time after page was rendered i got an error:

CDbException
Description

CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

Source File

C:\Projectos\MyLittleSystem\framework\db\CDbCommand.php(375)
0

#4 User is online   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,651
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 09 July 2010 - 10:48 AM

Just for the record, CHtml itself uses 'success'
if(isset($options['update']))
{
	if(!isset($options['success']))
		$options['success']='js:function(html){jQuery("'.$options['update'].'").html(html)}';
	unset($options['update']);
}
if(isset($options['replace']))
{
	if(!isset($options['success']))
		$options['success']='js:function(html){jQuery("'.$options['replace'].'").replaceWith(html)}';
	unset($options['replace']);
}

/Tommy
Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
0

#5 User is offline   koz 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 35
  • Joined: 23-June 10

Posted 09 July 2010 - 11:39 AM

View Posttri, on 09 July 2010 - 10:48 AM, said:

Just for the record, CHtml itself uses 'success'
if(isset($options['update']))
{
	if(!isset($options['success']))
		$options['success']='js:function(html){jQuery("'.$options['update'].'").html(html)}';
	unset($options['update']);
}
if(isset($options['replace']))
{
	if(!isset($options['success']))
		$options['success']='js:function(html){jQuery("'.$options['replace'].'").replaceWith(html)}';
	unset($options['replace']);
}

/Tommy


But it dont allow second parameter like:
("#contentDiv", window.parent.document)

right'?
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