The issue is the A in AJAX stands for asynchronous... this means that it won't wait for the sessions to be updated before loading the page... so it is a timing and order of operations issue.
You need to pass another argument to the ajax function call: async: false;
If you turn off asynchronous then it will wait for the session variables to be updated before opening the window.