douao3063 2014-03-12 06:08
浏览 51
已采纳

如何在PHP Session中存储JavaScript函数参数?

i have passed argument in JS method and that methods argument needs to save in PHP Session but failed to do so ....... CODE:

 function checkBoxStatusUser1(condition)
       {

           console.log("condition checkBoxStatusUser1 :"+condition);
           setStatusDataUser(condition);
            <?php
        Yii::app()->session['var'] = condition;
       print_r(Yii::app()->session['var']); // Prints "value"
?>

       }

BUT THIS LOC: Yii::app()->session['var'] = condition; is not assigning condition's value either true or false to the session

  • 写回答

1条回答 默认 最新

  • doubu1853 2014-03-12 06:10
    关注

    Use Ajax for this. If you want to send a javascript variable from client side to server side, you should make an ajax call and send the variable in the 'data' property of the object parameter of the ajax call.

    function checkBoxStatusUser1(condition) {
        console.log("condition checkBoxStatusUser1 :" + condition);
        setStatusDataUser(condition);
        $.ajax({
            url: '/requestHandler',
            data: {
                'condition': condition, //here you pass the data
            }
            type: 'post',
        });
    }
    

    And on server, make a script to handle request at '/requestHandler' and then do this-

     Yii::app()->session['var'] = $_POST['condition'];
    

    You can get a decent understanding of it here -

    http://www.w3schools.com/Ajax/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效