单击按钮时触发警报
当我单击该按钮时,不会执行警报。我做错了什么?也许我需要在标头部分包含一些 js 文件?
这是我的登录表单视图:
<?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>
这是我在控制器中的代码:
public function actionLogin()
{
$this->renderPartial('//blocks/user_info');
}
user_info 只是回显一些文本
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
不确定这是否是您的问题,但 renderPartial() 不能很好地与 AJAX 配合使用。这是一个已知的 Yii 问题:
http://www.yiiframework。 com/forum/index.php/topic/24699-yii-20-ajaxrenderpartial-conflict/
http://www.yiiframework.com/forum/index.php?/topic/10427-ajax-clientscript
当我尝试通过 AJAX 加载表单,然后使用 CHtml::ajaxSubmitButton 将其提交回来时,我遇到了问题。
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.
试试这个
<代码>
this->renderPartial('//blocks/user_info','', false, true);
try this
this->renderPartial('//blocks/user_info','', false, true);
在我的代码中它可以尝试这个
in my code it works try this
beforeSend 有效吗?如果你尝试“成功”而不是“完成”怎么办?
Does beforeSend work? What if you try "success" instead of "complete"?
我也有这个问题(bug?)。
尝试在此视图中更改“beforeSend”和其他回调:
不使用“function(){}”并使用“js”。
聚苯乙烯
抱歉,我的英语不好(
I have this problem(bug?) too.
Try change 'beforeSend' and other callbacks in this view:
without "function(){}" and with "js".
P.S.
Sorry, my English is bad(
这是 Yii Ajax 提交按钮的简单示例:
更多详细信息请访问 http://www.codexamples.com /90/chtml-ajaxsubmitbutton/
This is simple example of Yii Ajax Submit button:
More detail at http://www.codexamples.com/90/chtml-ajaxsubmitbutton/
视图中的 Ajax 提交按钮:
在控制器操作中:
根据要求更改返回数组。
Ajax submit button in view:
In Controller action:
Change return array as per requirement.
您必须将 renderPartial 函数的第四个参数设置为 true,以便 Yii 包含视图正常工作所需的 JS 文件。
You have to set the fourth parameter of renderPartial function to true, so that Yii will include the required JS files for the proper working of the view.
在控制器函数中,您需要再发送 3 个参数(总共 4 个参数),
您的函数将如下所示
In the controller function you need to send 3 more parameters (total 4 parameters)
your function will be like this