简体   繁体   中英

Passing and getting Values from Controller Action to Ajax Success - Yii Framework

I am new to yii Framework now I want to pass value from Controller action to Ajax on Success and by getting the value I have store it in php variable . How to achieve this ?

My Controller Action :

public function actionNewrefList($id)
    {
        $model=new RefListModel();
        // Uncomment the following line if AJAX validation is needed
        // $this->performAjaxValidation($model);

        if(isset($_POST['RefListModel']))
        {
            $model->attributes=$_POST['RefListModel'];
            $model->crm_base_contact_id=$id;
            if($model->save())
            {
                /** Here i need to send value of $model->crm_ref_list_id to Ajax Onsuccess **/
                return;
            }
        }


    }

My View Ajax:

echo CHTML::ajaxSubmitButton('Save', Yii::app()->createUrl('baseContact/NewrefList',array("id" => $base)),
           array('success' => 'js:function(){
    '))

Here I have to get the value passed from controller and store it in PHP Variable.

 if(isset($_POST['RefListModel']))
    {
        $model->attributes=$_POST['RefListModel'];
        $model->crm_base_contact_id=$id;
        if($model->save())
        {
            echo $model->crm_ref_list_id;
            Yii::app()->end();
        }
    }

In view:

echo CHTML::ajaxSubmitButton('Save', 
Yii::app()->createUrl('baseContact/NewrefList',
array("id" => $base)),
'success' => 'js:function(data){
    alert(data);
}'))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM