如何将多个值的输出从extjs发送到Yii控制器动作 [英] How to send output with multiple values from extjs to Yii controller action

查看:128
本文介绍了如何将多个值的输出从extjs发送到Yii控制器动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在extjs + yii工作。我的服务器端在yii框架中,客户端是extjs。现在我想通过extjs的提交按钮输出到yii动作。我在extj中创建20个问题的多项选择问题文件,其实际问题将来自于Yii framewok中的服务器端操作。直到此为止,它正常工作。



现在,通过标记各自的单选按钮作为答案解决所有问题后,点击提交按钮,我想发送这些对于yii控制器操作,有20个问题 userId questionId 和选定的单选按钮选项。我已经写了提交按钮动作:

  check:function()
{
console.log 内部检查功能);
//在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]
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);
}
}
}
}
});

所以我得到 questionId optionValue 提交按钮点击的所有问题。现在我想将所有的 questionid optionValue 数据发送到yii操作。那么如何将它发送到extjs动作?

解决方案

您应该将数据发布到控制器中的一个动作,使用AJAX
例如:site / savequestions

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

然后在控制器中 SiteController

  public function actionSavequestion()
{
$ questionId = Yii :: app() - > ;请求 - > getParam( 'QID');
$ anserId = Yii :: app() - > request-> getParam('aid');
// ...在这里做东西

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


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?

解决方案

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()
}

这篇关于如何将多个值的输出从extjs发送到Yii控制器动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆