I assume that your Javascript is code is inside the PHP script. if it is separate .js file then it may not work.
You can simply put this in your javascript portion of the code:
var session = <? print $session; ?>;
where $session is your own created session id.
When the php file is executed, your javascript code will contain the session.
Regards,
Masood Nasir
www.webx.net