dtcyv3985 2012-07-20 08:53
浏览 66
已采纳

如何在Zend中的视图之间传递数据列表?

I have two dropdown list which is question and answer. At first the answer dropdown list is empty, after the user choose a question, then it will pass the question_id to controller to run a function to get the answer. After the controller get the result, it will pass to the correspond view. Now how can I pass the result to the index view?

the index view:

$("#id_question").change(function() {
var data = $("#id_question").val();
var dataToSend = {question: data}
var href= '<?php echo $this->baseUrl('admin/comment/checkanswer'); ?>';

    $.ajax({ type: "POST",
        url: href,
        data: dataToSend,
        success: function(response){

                //do what u wana do
        }
        });
  });`

the controller:

public function checkanswerAction()
{
    $this->_helper->layout->disableLayout();

    $question_id = $this->getRequest()->getParam('question');

    $answer_model = new Admin_Model_DbTable_Answer();
$answer = $answer_model->getAnswersByQuestionId($question_id);

$this->view->answer = $answer;
  }

the checkanswer.phtml:

foreach ($this->answer as $key => $value)
     {
         echo '<option value="'.trim($value['id_answer']).'">'. trim($value['answer_text']) .'</option>';
       }
  • 写回答

3条回答 默认 最新

  • douou9094747 2012-07-20 08:57
    关注

    The content that should be displayed in checkanswer.phtml will be affected to your javascript var response. So if you want to display this in your page, you have to make something like this :

    success: function(response){
        //do what u wana do
        $('#yourSelectID').html(response);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么