简体   繁体   中英

Save jQuery variables in a PHP session

var x = e.pageX;
var y = e.pageY;

Which is the easiest way to save those jQuery variables in a PHP session.

$.ajax({
   url: '/update-session.php',
   data: {"x":e.pageX,"y":e.pageY},
   type: 'post',
   success:function(data){
       // if you care. 
   }
});

update-session.php:

$_SESSION['pageX'] = $_POST['x'];
$_SESSION['pageY'] = $_POST['y'];

http://api.jquery.com/jQuery.ajax/

Make an AJAX request to a PHP page that saves them in the session.

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