title: Using Ajax to get value of javascript variable?
body: <p>Long time stackoverflow user but first time poster! I recently made a very simple little browser based game, and when I say simple I cannot stress this enough.</p>
  
  <p>Anyway, the entire game logic is in one little javascript file. In that file I have a variable called value, and it contains the players score.</p>
  
  <p>The user at any given time during gameplay is allowed to click Submit, and this then uses a php script to access and write their username and hopefully soon their score to my database.</p>
  
  <p>The problem I am having and I know quite a few people new to Ajax have had is, how do I send the value of the javascript variable value to my php page which handles sending the variables to my database?</p>
  
  <p>I have read quite a bit on this and can't seem to get it working. So starting from scratch, assume I have a functioning javascript file with the value variable containing the score. How do I send the score to the php file using ajax? Where would I place the Ajax code?</p>
  
  <p>Thank you stackoverflow! Also I already know that javascript resides on the client side and php runs on the server side, I just would like to know how to properly send the score to the php file, that is all! Thanks again stackoverflow!</p>
  
  <p>EDIT: Because I seem to be getting down voted this is what I have but it does not work:</p>
  
  <p>My Ajax:</p>
  
  <pre><code>function ajaxCall() {alert("To AJAX: the value is: " + value);
  
      $.ajax
      (   {
              type: "POST",
              url: "handler.php",
              data: {'value' : value}, 
              success: function(response)
              { alert("The value was passed!")}
          }
      );};
  </code></pre>
  
  <p>ajaxCall();</p>
  
  <p>Part of handler.php:</p>
  
  <pre><code>if(isset($_POST['value']))
  
  {
  $value = $_POST['value']."";
  var_dump($value);
  }
  
  var_dump($_POST['value']);
  </code></pre>