php - Set Codeigniter Session in Jquery - Stack Overflow

I need to set session in Jquery but when i try it does not workthis is i am doing in jqueryvar a = 22;

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
 |  Show 4 more ments

2 Answers 2

Reset to default 6

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745002255a4605568.html

相关推荐

  • php - Set Codeigniter Session in Jquery - Stack Overflow

    I need to set session in Jquery but when i try it does not workthis is i am doing in jqueryvar a = 22;

    1天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信