I am very new to PHP and just starting to learn AJAX.
I want to know if its possible to change a PHP SESSION VARIABLE using AJAX and how to do it... I tried to check on some examples but most of it are just displaying some values on the browser.
Example: http://www.w3schools.com/php/php_ajax_php.asp
index.php:
<?php
$_SESSION['test'] = 1;
?>
<script type="text/javascript" src="functions.js" > </script>
<div>
<?php echo "Before: " . $_SESSION['test']; ?>
<input type="submit" value="CLICK" onclick="resetVar('<?php echo $_SESSION['test']; ?>')" />
<?php echo "After: " . $_SESSION['test']; ?>
</div>
functions.js:
function resetVar(sessionVal) {
sessionVal = null;
var httpRequest;
if(window.XMLHttpRequest) httpRequest = new XMLHttpRequest();
if(window.ActiveXObject) httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
if(httpRequest.readyState == 4 && httpRequest.status == 200) {
// I don't know what to put here...
}
httpRequest.open("get", "index.php?$_SESSION['test'] = " + sessionVal, true);
httpRequest.send();
}
I know its terribly wrong and I need help to fix this. I want AJAX to do a similar unset the $_SESSION['test'] variable when I hit the submit button. I want it to do someting like unset($_SESSION['test']). Please help me with this...