title: Pass var from js to php using ajax not working
body: <p>I'm making a calculator web app in PHP. The front end is using HTML, CSS, and JS. In my JS file, I am trying to pass a var to PHP using ajax. Here's what I have so far:</p>
  
  <pre><code>// Get all the keys from document
  var keys = document.querySelectorAll('#calc span');
  var operators = ['+', '-', 'x', '÷'];
  var decimalAdded = false;
  
  // Add onclick event to all the keys and perform operations
  for(var i = 0; i &lt; keys.length; i++) {
  keys[i].onclick = function(e) {
      // Get the input and button values
      var input = document.querySelector('.screen');
      var inputVal = input.innerHTML;
      var btnVal = this.innerHTML;
  
      // Now, just append the key values (btnValue) to the input string and finally use javascript's eval function to get the result
      // If clear key is pressed, erase everything
      if(btnVal == 'C' || btnVal == 'AC') {
          input.innerHTML = '';
          decimalAdded = false;
      }
  
      // If eval key is pressed, calculate and display the result
      else if(btnVal == '=') {
          var equation = inputVal;
          var lastChar = equation[equation.length - 1];
  
          // Replace all instances of x and ÷ with * and / respectively. This can be done easily using regex and the 'g' tag which will replace all instances of the matched character/substring
          equation = equation.replace(/x/g, '*').replace(/÷/g, '/');
          $.ajax({
              type: "GET",
              url: "calc.php",
              data: {'passVal': equation},
              success: function(data) {
  
                      alert(data);
  
              }
          });
  </code></pre>
  
  <p>I'm not seeing anything in my alerts and it's also not posting to php file I specified. If I do the following on the other hand, I get my data in the alert but still not sure how to pass to php file:</p>
  
  <pre><code>....rest of code
     $.ajax({
              type: "POST",
              url: "calc.php",
              data: {'passVal': equation},
              success: function(data) {
                      alert(equation);
               }
          });
  </code></pre>