4

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

2 Answers 2

6

Try 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

Sign up to request clarification or add additional context in comments.

1 Comment

Could we see your url rules from the config? And did you try 'actions'=>array('index','view', 'test', 'ajaxRequest'), putting upper case for "ajaxrequest" ?
-1

try this

url: $(location).attr('pathname') + '?r=anyControllerId/actionId',

This will get the path name of the current URL

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.