如何将具有多个值的输出从 extjs 发送到 Yii 控制器操作 [英] How to send output with multiple values from extjs to Yii controller action
问题描述
我在 extjs+yii 工作.我的服务器端在 yii 框架中,客户端在 extjs 中.现在我想将 extjs 的提交按钮输出传递给 yii 操作.我正在 extjs 中创建 20 个问题的选择题试卷,其实际问题将来自用 Yii 框架编写的服务器端操作.到目前为止,它工作正常.
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.
现在通过将其各自的单选按钮标记为答案来解决所有问题后,单击提交按钮我想发送这 20 个问题 userId
, questionId
并选择yii 控制器操作的单选按钮选项.我已将提交按钮操作编写为:
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);
}
}
}
}
});
所以我在点击提交按钮时得到了所有问题的 questionId
和 optionValue
.现在我想将所有 questionid
和 optionValue
数据发送到 yii action.那么如何发送给extjs action呢?
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?
推荐答案
您应该使用 AJAX 将数据发布到控制器中的操作例如:站点/保存问题
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' }
});
然后在控制器 SiteController
中你会
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屋!