admin管理员组文章数量:1300006
For some reason this doesnt work and I can't find a way to make it work!
on my controller named "ExplicacaoController" I have this:
public function accessRules()
...
'actions'=>array('index','view', 'test', 'ajaxrequest'),
...
public function actionAjaxRequest()
{
$val1 = $_POST['val1'];
$val2 = $_POST['val2'];
echo "something";
Yii::app()->end();
}
On my view I have:
<script type="text/javascript">
...
$.ajax({
type: "POST",
url: "<? echo Yii::app()->createUrl('explicacaoController/ajaxRequest'); ?>",
data: {val1:1,val2:2},
success: function(msg){
alert("Sucess")
},
error: function(xhr){
alert("failure"+xhr.readyState+this.url)
}
});
...
What happens is that I allways get this error:
failure4<? echo Yii::app()->createUrl('explicacaoController/ajaxRequest'); ?>
I really need some help with this
For some reason this doesnt work and I can't find a way to make it work!
on my controller named "ExplicacaoController" I have this:
public function accessRules()
...
'actions'=>array('index','view', 'test', 'ajaxrequest'),
...
public function actionAjaxRequest()
{
$val1 = $_POST['val1'];
$val2 = $_POST['val2'];
echo "something";
Yii::app()->end();
}
On my view I have:
<script type="text/javascript">
...
$.ajax({
type: "POST",
url: "<? echo Yii::app()->createUrl('explicacaoController/ajaxRequest'); ?>",
data: {val1:1,val2:2},
success: function(msg){
alert("Sucess")
},
error: function(xhr){
alert("failure"+xhr.readyState+this.url)
}
});
...
What happens is that I allways get this error:
failure4<? echo Yii::app()->createUrl('explicacaoController/ajaxRequest'); ?>
I really need some help with this
Share Improve this question edited Jan 25, 2014 at 6:35 talha2k 25.5k4 gold badges65 silver badges82 bronze badges asked Nov 20, 2012 at 12:50 user1772093user1772093 871 gold badge2 silver badges8 bronze badges2 Answers
Reset to default 6Try to put
<? echo Yii::app()->createUrl('Explicacao/ajaxRequest'); ?>
instead of
<? echo Yii::app()->createUrl('explicacaoController/ajaxRequest'); ?>
The thing is in create url you need to put the Controller ID not the Controller full name.
If it's not working you could try both Explicacao/ajaxRequest
or explicacao/ajaxRequest
because your rout could be case sensitive depending on your conf
try this
url: $(location).attr('pathname') + '?r=anyControllerId/actionId',
This will get the path name of the current URL
本文标签: phpajax call controller in yii (javascript)Stack Overflow
版权声明:本文标题:php - ajax call controller in yii (javascript) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741654515a2390678.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论