newbie here. i'm experimenting with ajax and php lately just for learning purposes, i have this simple html:
<button type="button" id="setc">Set Cookie</button>
on click i want to ask for a variablename and value so i could pass it on my php script, here's my js code:
$("#setc").click(function(){
var cookieVar = prompt("Enter a cookie variable","");
var cookieVal = prompt("Enter the variable's value","");
$.ajax({
url:'setcookie.php',
type: 'POST',
data: "cookieVar="+cookieVar+"&cookieVal="+cookieVal,
success:function(data){
console.log(data);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
console.log(textStatus+errorThrown);
}
});
});
and here's my php script:
<?php
$cookieVar="";
$cookieVal="";
echo setcookie($cookieVar,$cookieVal);
?>
but when i clicked the button it gives me this error:
"Warning: Cookie names must not be empty in D:\xampp\htdocs\phpcustomsite\setcookie.php on line 4"
how can i make it work?