most simple AJAX request fails!!!

This has been driving me crazy:It’s a simple ajax link that makes a POST request to an action.The code inside the action is never executed,instead I get 400 CHttpException,Your request is invalid.

The ajax link




    <?php echo CHtml::ajaxLink('test', $this->createUrl('/yms/article/test'), array('data'=>array('id'=>53),'type'=>'POST'))?>



and then is yms module,I have a simple test action in article controller





 public function actionTest($id)

	{

      echo json_encode($id);

        }



.My original action was more involved,but I stripped it out to find the problem,but now even this basic ajax request fails.

I have written hundrends of ajax requests,both with Yii helpers and custom,this does not make any sense at all.

I will appreciate your help.

Um,this is embarassing .The ajax request succeeds,if the action function has no argument.If it does,it seems like it expects a GET ajax request,which I tried and also succeeded.Strange,I thought the action argument would pick up both GET and POST variables.

I am a beginner. It looks like most GET and POST can not happen at the same time. Is this correct?

Action Parameter Binding uses only the $_GET variables - http://www.yiiframework.com/doc/guide/1.1/en/basics.controller#action-parameter-binding

@nettrinity

To make GET and POST request at the same time you can do it like:




<?php echo CHtml::ajaxLink('test', 

	$this->createUrl('test',array('id'=>53)), 

	array('data'=>array('name'=>'testing'),

	'type'=>'POST'

))?>



This way in the actionTest you can read those two variables like $_GET[‘id’] and $_POST[‘name’]

Thanks a lot mdomba! How did you know this?

Much much practice… and experience… ;)

yep same issue. thanks alot drumaddict n mdomba

In your controller you can also do this,


    public function getActionParams()

    {

        return array_merge($_GET, $_POST);

    }

Will merge POST and GET variables.