I have a page that after opened, make a serie of ajax posts to a notification endpoint. I would like to persist data across the posts using a guest session. No login, but context control regardless. I am using cookies.
I am having issues to restore objects from the session is these ajax requests (they come null), and I noticed that on each post to the notification endpoint, I get a different value for request()->session()->getId()
, which makes me think the session is not being communicated properly and that's why I don't see the objects I expected to see persisted.
My URLs are using the "web" middleware.
Everytime the page open I do:
<script>
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': '<?php echo csrf_token(); ?>'
}
});
</script>
To ensure ajax requests will have the CSRF token in the header
I also do 'request()->session()->regenerate();'everytime the page opens (not in the notifications) to ensure a new session.
Is there anything else (perhaps pass values from cookies) that I should send in the POST to identify the request as part of a context?