Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Codeigniter Session in Jquery

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.


1 Answers

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

like image 85
Alessandro Minoccheri Avatar answered Aug 10 '26 22:08

Alessandro Minoccheri



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!