4777
In image showing two ajax button showed. While page loading ajax button id created like yt0,yt1,yt2… etc.
then I loaded part of page using ajax then again it created ajax button yt0,yt1, like that…
I want to create another ajax button series like yw0 or something like that…
How to do that???
lagogz
(Lagocamanho)
October 11, 2013, 12:51pm
2
I suppose you want to identify the buttons, then, why don’t you set id property for AjaxSubmitButton?
CHtml::ajaxSubmitButton(
'the button label',
'the URL for the AJAX request',
'AJAX options',
array('id' => 'desiredId') // HTML options for the button.
);
Regards.
zaccaria
(Matteo Falsitta)
October 11, 2013, 1:00pm
3
Yii is a php framework, the CHtml::ajaxbutton is intended to be an helper, not an althernative to jquery ajax.
If you are going to do more complicated works with ajax, be prepared to write your own js code instead of use yii helpers.
lagogz:
I suppose you want to identify the buttons, then, why don’t you set id property for AjaxSubmitButton?
CHtml::ajaxSubmitButton(
'the button label',
'the URL for the AJAX request',
'AJAX options',
array('id' => 'desiredId') // HTML options for the button.
);
Regards.
Thanks for your reply…
I cant give ID as static bcoz like that more ajax content will get load, then every button id will be the same.
It wont work unless I give dynamic id.
zaccaria
(Matteo Falsitta)
October 14, 2013, 8:28am
5
This is a typical problem of the helpers.
The helpers get a dynamic id like yt0, yt1 and the counter is restarted at each render.
So you load ajax content that has the same counter and the same id.
A pure js solution is not to use the yii helpers, which are great but does not cover all cases, and use a js instead.
For example you can give a class to the button and then register the script:
$('body').delegate('.myclass', 'click', function(e){
e.preventDefault();
//do something
});
If all the button are suposed to do the same you can just delegate, as delegate works with all instances, even "future" one.
4777
In image showing two ajax button showed. While page loading ajax button id created like yt0,yt1,yt2… etc.
then I loaded part of page using ajax then again it created ajax button yt0,yt1, like that…
I want to create another ajax button series like yw0 or something like that…
How to do that???
Hi,
<?php echo CHtml::ajaxButton(‘ajaxbutton’,
Yii::app()->createUrl('post',array('pid'=>$post->post_id)),
array(
'type'=>'POST',
'beforeSend' => "function(request)
{
//alert('heelo'+request)
}",
'success' => "function(data)
{
//alert (data)
$('.form').html(data);
}",
'error' => "function(data)
{
// handle return data
alert('erro'+data);
}",
'data' => 'js:$("#detail-form").serialize()',
),
array('id'=>'scopy'.rand(),'live'=>false,
'href' => Yii::app()->createUrl('post',array('postid'=>$post->post_id))
)
);
?>
Try this way. I hope it should work.
Thanks
chandran nepolean