Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
145
rated 0 times [  146] [ 1]  / answers: 1 / hits: 36369  / 9 Years ago, wed, december 30, 2015, 12:00:00

I have a javascript code like this :



<script type=text/javascript>

$('#editRole').on('show.bs.modal', function (e) {

$roleID = $(e.relatedTarget).attr('data-id');
// Here I want to set this $roleID in session may be like this :
Session['roleID'] = $roleID;
});

</script>


Then I want to get that $roleID in an other place using php code, may be like this :



<?php $roleID = Session::get('roleID'); //do something ....  ?>


Thanks


More From » php

 Answers
7

You can't set a server session variable directly from JS.



To do that you can make an AJAX call to a PHP script passing the value you want to set, and set it server side:



$('#editRole').on('show.bs.modal', function (e) {  

$roleID = $(e.relatedTarget).attr('data-id');

//ajax call
$.ajax({
url: set_session.php,
data: { role: $roleID }
});
});


set_session.php



//preliminary code

Session::put('roleID', $request->input('role') );

[#63889] Monday, December 28, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sageallenv

Total Points: 458
Total Questions: 102
Total Answers: 104

Location: Venezuela
Member since Thu, Jul 15, 2021
3 Years ago
;