If your using AJAX then you can't use the method your trying to employ, your PHP script ouput would have ot be echoed out so the returning query is either a straight number or string.
So ...
AjaxObj = new XMLHttpRequest();
AjaxObj.open("GET","yourphpscript.php",true);
AjaxObj.onreadystatchange = function(){
if(AjaxObj.readyState == 4 && AjaxObj.status == 200){
theResponse = AjaxObj.responseText;
}
}
AjaxObj.send();
as a rough example, then your script that is "yourphpscript.php" would be like
<?php
echo "your string";
?>
so that all that is returned to AJAX is your string to theResponse variable
What you do after that is up to you.
If you want to write javascript variables from PHP when the page is being rendered then the previous example is what you need.
What you seem to be doing is mixing Javascript and PHP up and you can't render PHP clientside as its a serverside scripting language.