Php sessions persistance

I have a page that makes calls via JavaScript (fetch) another modx page with a snippet on it to get data and format the result, I have found that I even if I use unset($_SESSION[“Data”]);
and session_destroy(); When I refresh the page the session variable is still set.
If I set use and unset session variables in a snippet within the page I am using for example index.php?id=2 it is fine, but if I use javascript to call say index.php?id=6 to get data and unset the session variable it will do it locally with the snippet but refresh and the session variable can still be accessed.
I am probably not understanding the scope here so would some please help me understand.
modxcloud modx 2.8.1 php 7


Perhaps the endpoint for your ajax/fetch call quits the process in a non-standard way without explicitly calling @session_write_close(); causing it to not write the updated session?

Or perhaps the ajax requests happen to be on a different origin (domain/path) that is unable of updating the cookie?

Nice one Mark, I will try the session_write_close as the ajax call is same domain with the only difference being page id.
I did find another strange behavior, if I don’t start a session on the page, from a direct call to a snippet but start it in the ajax call to the a second page that session becomes a sort of persistent session across different browsers and devices. It is as if the server/ ajax call owns the session but it is not connected to the browser, what do you make of that?