简体   繁体   中英

how to unset session in javascript on slider change

How can I unset a session using javscript. I know this can't be done in javascript alone but we have to call a php script. I want to unset the session on the change of my sldier value. ie

 $('#slider1').bind('change', function (event) {
                        $('#slider1Values').html('Value: ' + event.args.value.toFixed(2));
                   //I want to unset the session here
                    });

I found some post where we can unset it in a button click by redirecting to another php page where I can call the php script to unset the session. I want something which unsets a session on the change of the slider without redirecting it into another page if possible. I saw it can be done using ajax but could not find an example. If any links or source please provide. Is this possible by doing?

var a=<?php  unset($_SESSION['data']);?>;

if jquery is on the table then it's pretty easy to perform a session value unset.

First off create a php file that does the actual unset

<?php 
// unset_data.php
session_start();
unset($_SESSION["data"]);
?>

Then on your change event from the slider.

$('#slider1').bind('change', function (event) {
     $('#slider1Values').html('Value: ' + event.args.value.toFixed(2));
     $.ajax("/unset_data.php", {"cache":false});
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM