title: AJAX PHP, on button click pass variable from javascript prompt to php script to set cookie?
body: <p>newbie here. i'm experimenting with ajax and php lately just for learning purposes, i have this simple html: </p>
  
  <pre><code>&lt;button type="button" id="setc"&gt;Set Cookie&lt;/button&gt;
  </code></pre>
  
  <p>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:</p>
  
  <pre><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+"&amp;cookieVal="+cookieVal,
          success:function(data){
              console.log(data);
          },
          error: function(XMLHttpRequest, textStatus, errorThrown) {
              console.log(textStatus+errorThrown);
           }
      });
  });
  </code></pre>
  
  <p>and here's my php script:</p>
  
  <pre><code>&lt;?php
      $cookieVar="";
      $cookieVal="";
      echo setcookie($cookieVar,$cookieVal);
  ?&gt;
  </code></pre>
  
  <p>but when i clicked the button it gives me this error:</p>
  
  <p>"<b>Warning</b>:  Cookie names must not be empty in <b>D:\xampp\htdocs\phpcustomsite\setcookie.php</b> on line <b>4</b>"</p>
  
  <p>how can i make it work?</p>