How to send output with multiple values from extjs to Yii controller action

∥☆過路亽.° 提交于 2019-12-02 19:20:43

问题


I am working in extjs+yii. My server side is in yii framework and client side is in extjs. Now I want to pass extjs's submit buttons output to yii action. I am creating multiple choice question paper of 20 questions in extjs whose actual questions will come from server side action which is written in Yii framewok. Up to this, it is working correctly.

Now after solving all questions by marking its respective radio buttons as an answer, on the click of submit button I want to send these 20 questions userId, questionId and selected radio buttons option to yii controller action. I had written submit button action as:

     check:function()
            {
        console.log("Inside check function.");
        //creating objects in javascript
          var obj=new Object();
          for(var i=0;i<=5;i++)
          {
                var inputs = document.getElementsByName(i); 
                var radio = "";  
                for (var j = 0; j < inputs.length; j++) {
                    if (inputs[j].checked) {
                        name = inputs[j].name;
                        value  = inputs[j].value;
                        //obj[i].name1=name;
                        obj[i]={'questionId':name,'option':value};
                        console.log("questionId="+name +" value="+ value);
                        console.log("object name="+ obj[i].questionNo+" Object value="+obj[i].option);
                    }
                }
          }
    }
});

So I am getting questionId and optionValue of all questions on submit button click. Now I want to send all the questionid and optionValue data to yii action. So how to send it to extjs action?


回答1:


You should post your data to an action in a controller with AJAX for example : site/savequestions

   Ext.Ajax.request({
        url:"site/savequestions",
        method: "POST",
        params: {'qid': name, 'aid':value},
        success: function(){
            console.log("ok");
        },
        failure: function(response, opts){
            console.log("failed");
        },
        headers: { 'Content-Type': 'application/json' }
    });

and then in the controller SiteController you would have

public function actionSavequestion()
{
    $questionId = Yii::app()->request->getParam('qid');
    $anserId = Yii::app()->request->getParam('aid');
    //... do stuff here

    echo json_encode(array('success' => true));
    exit()
}


来源:https://stackoverflow.com/questions/14277666/how-to-send-output-with-multiple-values-from-extjs-to-yii-controller-action

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!