When I click the button, alerts aren't performed. What am I doing wrong? Maybe I need to include some js files in my header section?
Here is my login form view:
<?php echo CHtml::beginForm(); ?>
<div class="row">
<?php echo CHtml::label('username', 'username'); ?>
<?php echo CHtml::textField('username'); ?>
</div>
<div class="row">
<?php echo CHtml::label('password', 'password'); ?>
<?php echo CHtml::textField('password'); ?>
</div>
<?php
echo CHtml::ajaxButton('sign in', array('site/login'),array(
'type'=>'POST',
'update'=>'#mydiv',
'beforeSend' => 'function(){
alert("beforeSend");
}',
'complete' => 'function(){
alert("complete");
}',
));
?>
<?php echo CHtml::endForm(); ?>
<div id="mydiv" style="color:white;">...</div>
Here is my code in the controller:
public function actionLogin()
{
$this->renderPartial('//blocks/user_info');
}
user_info just echoes some text
Closing Alerts To close the alert message, add a . alert-dismissible class to the alert container. Then add class="close" and data-dismiss="alert" to a link or a button element (when you click on this the alert box will disappear).
Add break; at the end of an event and modify your ifthenelse block to reload window when true.
showCancelButton and showConfirmButton are no longer needed. Instead, you can set buttons: true to show both buttons, or buttons: false to hide all buttons. By default, only the confirm button is shown.
How do you pop up an alert box when the browsers refresh button is clicked? You can do it like this: window. onbeforeunload = function() { return “Data will be lost if you leave the page, are you sure?”; };
Not sure if this is your problem, but renderPartial() does not play well with AJAX. It is a known Yii issue:
http://www.yiiframework.com/forum/index.php/topic/24699-yii-20-ajaxrenderpartial-conflict/ http://www.yiiframework.com/forum/index.php?/topic/10427-ajax-clientscript
I ran into the problem when I tried to load a form via AJAX, then submit it back using CHtml::ajaxSubmitButton.
try this
this->renderPartial('//blocks/user_info','', false, true);
in my code it works try this
<?php
echo CHtml::ajaxSubmitButton('Save','your-url',array(
'type'=>'POST',
'dataType'=>'json',
'success'=>'js:function(data){
if(data.result==="success"){
// do something on success, like redirect
}else{
$("#some-container").html(data.msg);
}
}',
));
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With