Is it possible to a create session variable in JavaScript?

后端 未结 5 1485
情歌与酒
情歌与酒 2021-01-05 09:50

Is it possible to create and update a session variable in JavaScript? Just like in PHP as I start sessions and initialize session variable.

I\'m using some JavaScrip

5条回答
  •  孤街浪徒
    2021-01-05 10:13

    Well, taking a look at how sessions work, no, they cannot be created with javascript. You can, though, make an AJAX request to your PHP file to set one.

    PHP:

    
    

    JS:

    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open("GET", "session_maker.php", true);
    
    xmlhttp.onreadystatechange = function(){
        if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
            alert("Done! Session created.");
        }
    };
    

提交回复
热议问题