Just a follow-up, for anyone who might need this in the future:
I couldn’t figure out why the sessions weren’t being carried over, even when session_start() was called at the start of the script. I tried everything I could think of, and I settled for a much less elegant solution at first. Basically, on the main page (where the AJAX request would initially take place), I set two cookies: one for the user’s id, and another for the user’s password hash, both of which were already stored as session data. During the AJAX request I simply validated the data by calling getWebUserInfo() (for the real password) and comparing them to check that they’re really the user. Then I got the user’s web groups and went from there.
Evidently, not the best solution, and not much in terms of finesse. After some digging, I realized that (silly me!) MODx sessions are named when you first run the installer (and therefore, calling session_start() would naturally have no effect unless you told it
what the name of the session is). So all I did was call startCMSSession() after including the MODx config file in my script, and BINGO, everything works flawlessly. Doh!
So if you need your external AJAX scripts to validate users or take advantage of certain MODx API functions (getWebUserInfo(), getLoginUserId(), etc), call startCMSSession() after including the config file for MODx and you’ll be all set.
I hope this helps someone!