I'm newbie to php, I would like to delete cookies with onClick event, I'm trying with some code but it doesn't work, this is what I tried, how can I fix it for it to work?
<html>
<head>
<body>
<button id="button" onClick='deleteCookie()'>Delete</button>
<script>
function deleteCookie(){
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if ( xmlhttp.readyState == 4 ) {
if ( xmlhttp.status == 200 ) {
unset($_COOKIE['user']);
}
}
xmlhttp.open( "GET", "cookie.php", true );
xmlhttp.send();
}
}
</script>
</body>
</head>
</html>