Set Session variable using javascript in PHP

后端 未结 9 981
刺人心
刺人心 2020-11-27 21:23

Is it possible to set PHP session variables using Javascript?

9条回答
  •  南笙
    南笙 (楼主)
    2020-11-27 22:13

    I solved this question using Ajax. What I do is make an ajax call to a PHP page where the value that passes will be saved in session.

    The example that I am going to show you, what I do is that when you change the value of the number of items to show in a datatable, that value is saved in session.

    $('#table-campus').on( 'length.dt', function ( e, settings, len ) {
        $.ajax ({
           data:        {"numElems": len},
           url:        '../../Utiles/GuardarNumElems.php',
           type:        'post'
        }); 
    });
    

    And the GuardarNumElems.php is as following:

    
    

提交回复
热议问题