anupam_sam
(Anupam Sam)
February 10, 2011, 6:35pm
1
i’m trying to delete some table rows using ajaxLinks placed in a CActiveForm but its not sending the data specified in the ajax data options rathar something weird :
[ _ ] => 1297379479430
ajaxLink code:
<?php
$form = $this->beginWidget('CActiveForm', array(
'id' => 'service-form',
'enableAjaxValidation' => false,
));
?>
......
......
<?php echo CHtml::ajaxLink('Delete', 'cas/index.php?r=service/deletetaskajax', array(
'ajax'=>array(
'type'=>'get',
'success'=>'function(data){$(this).parent().parent().remove();}',
'data'=>array('taskId'=>'5'),)),
array('id'=>'deleteRow')); ?>
......
when i use ajaxSubmitButton it Posts the whole CActiveForm Values.
Edit: just changed the original post to make it more precise.
mdomba
(Maurizio Domba Cerin)
February 11, 2011, 8:42am
2
As you are using the ajaxLink (check the documentation)… the 3rd parameter should be the ajax options… but you are here instantiating another ajax call… so its an ajax call on an ajax call… that leads to unpredictable results…
So your code should be like:
<?php echo CHtml::ajaxLink('Delete', '', array(
'type'=>'post',
'success'=>'function(data){alert("OK");}',
'data'=>array('taskId'=>'5')
),
array('id'=>'deleteRow')); ?>
anupam_sam
(Anupam Sam)
February 11, 2011, 9:07am
3
mdomba:
As you are using the ajaxLink (check the documentation)… the 3rd parameter should be the ajax options… but you are here instantiating another ajax call… so its an ajax call on an ajax call… that leads to unpredictable results…
So your code should be like:
<?php echo CHtml::ajaxLink('Delete', '', array(
'type'=>'post',
'success'=>'function(data){alert("OK");}',
'data'=>array('taskId'=>'5')
),
array('id'=>'deleteRow')); ?>
where to specify the url then?
Yeah i followed as its in the documentation.
public static string ajaxLink(string $text, mixed $url, array $ajaxOptions=array ( ), array $htmlOptions=array ( ))
the second parameter is the URL and 3rd is the ajax options. so i given the action url in the 2nd.
Basically the problem is that the GET or POST data variables are somehow encoded to something else.
[taskId]=>'5'
becomes
[_]=>'1297415912485'
All other things are working fine, i get the proper response too from the action specified here in the url.
anupam_sam
(Anupam Sam)
February 11, 2011, 3:36pm
4
Used to work it this way now.
Row gets deleted, echo gets displayed but success, complete or error nothing runs.
echo CHtml::ajaxLink('Delete', bu().'/index.php?r=service/deletetaskajax&id='.$task->id,
array('ajax'=>array(
'success'=>'function(){alert(\'Task Deleted!\');}',
'complete'=>'function(data){alert(data);}',
'error'=>'function(){alert(\'error\');}',
)),array(
'id'=>'deleteRow'));
any clue…
mdomba
(Maurizio Domba Cerin)
February 11, 2011, 5:02pm
5
Read again my comment #2 … you again put an ajax call inside another ajax call…
anupam_sam
(Anupam Sam)
February 11, 2011, 6:33pm
6
Ohhhh… this is insanely bad of me
i put the ‘ajax’ options array inside.
Thanks mdomba