According to your idea and your requirements, if you can't use a library like jQuery or Prototype, and so on... you are enforced to use the "raw" XMLHttpRequest Object. The following code is an example.
Create a file called ajax_js_enabled_test.php and put this code inside:
<?php
if(isset($_GET['PHPSESSID'])) session_id($_GET['PHPSESSID']);
session_start();
if(isset($_SESSION['user_js_support']) && $_SESSION['user_js_support']) echo "Javascript enabled";
else $_SESSION['user_js_support'] = FALSE;
?>
<script type="text/javascript">
var XHR;
if (window.XMLHttpRequest){
// The code for IE7+, Firefox, Chrome, Opera, Safari
XHR=new XMLHttpRequest();
}else{
// The code for IE6, IE5
XHR=new ActiveXObject("Microsoft.XMLHTTP");
}
XHR.open("GET","http://127.0.0.1/check_js_user_support.php<?php echo '?PHPSESSID='.session_id(); ?>",true);
XHR.send();
</script>
<p>
<a href="<?php echo '?PHPSESSID='.session_id(); ?>">
Refresh
</a>
</p>
Create another file called check_js_user_support.php and put this code inside:
<?php
if(isset($_GET['PHPSESSID'])) session_id($_GET['PHPSESSID']);
session_start();
$_SESSION['user_js_support'] = TRUE;
?>
Copy both files in your local web server root. Open the page ajax_js_enabled_test.php from your browser. The AJAX request starts and the page check_js_user_support.php will set the session param called user_js_support to TRUE. So by pushing the Refresh button the page will be reloaded, the $_SESSION['user_js_support'] will be TRUE and the script will write: "Javascript enabled"