I need to post something in ajax , and save it in sessions
This is the post code :
$(document).ready(function(){
$(".q").on('change', function postinput(){
var q = $(this).val(); // this.value
var id = $(this).attr("id"); // this.id
$.ajax({
url: 'api/save?id='+id+'&q='+q,
type: 'get'
}).done(function(responseData) {
console.log('Done: ', responseData);
}).fail(function() {
console.log('Failed');
});
});
});
And the api code :
session_start()
$id=$_GET['id'];
$_SESSION[$id] = $_GET['q'];
echo 'success';
I used var_dump($_SESSION); to show all sessions
I enter api/save?id=8&q=4 , it print:
array(2) { [""]=> NULL [8]=> string(1) "4" }
But if I enter api/save , it print :
array(1) { [""]=> NULL }