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.
Share Improve this question asked Mar 12, 2013 at 13:13 user2081972user2081972 9- 1 you cannot insert into a var php a var javascript/jquery, PHP is server side javascript/jquery is clienti side – Alessandro Minoccheri Commented Mar 12, 2013 at 13:14
- What you are trying to achieve? – Samy Commented Mar 12, 2013 at 13:15
- You cannot pass a jQuery/javascript variable to PHP. PHP is run on the server before transmitting, jQuery/javascript is run client side. You should look into AJAX as the solution to your problem. – Jacob Tomlinson Commented Mar 12, 2013 at 13:15
- there is no way to solve this? – user2081972 Commented Mar 12, 2013 at 13:15
- 1 you can make an ajax @AyshaAli – Alessandro Minoccheri Commented Mar 12, 2013 at 13:16
2 Answers
Reset to default 6in 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
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745002255a4605568.html
评论列表(0条)