在控制器中传递js变量但不在url:yii中显示参数

时间:2015-11-24 10:12:56

标签: javascript php yii

我从我的javascript函数中获取列表。现在我必须将列表传递给控制器​​并访问我的控制器中的列表。我不想在我的url中显示传递的参数。如何做到这一点?

我的java脚本代码是:

    <script type="text/javascript" language="JavaScript">
      function act()
      { 
     var idList = $.fn.yiiGridView.getChecked("marketing-grid", "selectedIds");
     if(idList!="")
         {

  var parIdList = $.param({ 'idList': idList });
               window.location.href= '<?php echo Yii::app()->createUrl('marketing/composeMail'); ?>'+ '?'+parIdList;

           }
            else
             {
              alert("Please select row to Mail.");
                 }
              }
          </script> 
  

我的控制器代码是:

 public function actionComposeMail()
{   
    $model=new Reply;
    $model->scenario = 'compose';
    $this->render('_compose',array('model'=>$model,//'model1'=>$modelMarket));
}
  

我必须在我的控制器中传递idList并在我的函数actionComposeMail()中获取该列表。

1 个答案:

答案 0 :(得分:2)

在视图中:

    <script type="text/javascript" language="JavaScript">
        function act() {
            var idList = $.fn.yiiGridView.getChecked("marketing-grid", "selectedIds");
            if (idList != "") {
                var url = '<?php echo $this->createUrl("marketing/composeMail"); ?>';
                var parIdList = $.param({ 'idList': idList });
                window.open(url+'?'+parIdList);
            } else {
                alert("Please select row to Mail.");
            }
        }
    </script>

在控制器中:

public function actionComposeMail($idList)
{   
    // or $idList = Yii::app()->request->getQuery('idList');

    $model=new Reply;
    $model->scenario = 'compose';
    $this->render('_compose',array('model'=>$model,//'model1'=>$modelMarket));
}