I need to set session in Jquery but when i try it does not work this is i am doing in jquery
var a = 22;
<?php $this->session->set_userdata('friend_id' ,a )?>
it gives me syntax error, anyone knows how to solve it.
I need to set session in Jquery but when i try it does not work this is i am doing in jquery
var a = 22;
<?php $this->session->set_userdata('friend_id' ,a )?>
it gives me syntax error, anyone knows how to solve it.
in jquery you can do this:
$.ajax({
type: "POST",
url: 'test.php',
data: '{"var":"yourvar"}',
success: function (data) {
console.log("Success!!");
},
error: function (xhr, desc, err) {
console.log('error');
}
});
and after into your file test.php
<?php $this->session->set_userdata('friend_id' ,$_POST['var'] )?>
MANUAL
You can use hidden field to do this
<input type="hidden" value="" name="id" id="id" />
this will in your js
var a = 22;
document.getElementById('id').value = a;
hope this will help you to solve your problem, but you can't set session in Jquery