title: How to post values through Ajax in php?
body: <pre><code>&lt;?php
  session_start();
  ?&gt;
      &lt;?php
          $con=mysqli_connect("localhost","root","") or die(mysqli_error());
          mysqli_select_db($con, "sada_r_t_m");
          $result=mysqli_query($con, "SELECT * FROM products ");
  
  echo "&lt;h2 fontsize = '26' color = 'yellow' align = 'center'&gt;Flipkart&lt;/h2&gt;";
  
  echo "&lt;table border = '5' cellpadding = '12' align = 'center' background-color = '#84ed86' color =  '#761a9b' &gt;";
  echo "&lt;tr&gt;";
  echo "&lt;th&gt;SNO&lt;/th&gt;";
  echo "&lt;th&gt;Product Name&lt;/th&gt;";
  echo "&lt;th&gt;Price&lt;/th&gt;";
  echo "&lt;th&gt;Cart&lt;/th&gt;";
  
  echo "&lt;/tr&gt;";
  while($data = mysqli_fetch_assoc($result))
  {
  echo "&lt;tr&gt;";
  echo "&lt;th&gt;".$data['id']."&lt;/th&gt;";
  echo "&lt;th&gt;".$data['name']."&lt;/th&gt;";
  echo "&lt;th&gt;".$data['price']."&lt;/th&gt;";
  echo "&lt;th&gt;&lt;a href='#' Onclick='add(".$data['id'].")'&gt;Add to Cart&lt;/a&gt;&lt;/th&gt;";
  
  echo "&lt;/tr&gt;";
  
  }
  echo "&lt;/table&gt;";
  ?&gt;
  &lt;script type="text/javascript"&gt;
  function add(id){
      alert(id);
  
      $.ajax({
          url: '../ajax.php',
          type: 'POST',
          data: { action: "add",id: id, val:1} ,
          //contentType: 'application/json; charset=utf-8',
          success: function (response) {
              alert(response.status);
          },
          error: function () {
              alert("error");
          }
      }); 
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>I passed the values through ajax in php. I wrote only in single php page.</p>
  
  <p>How to pass values through ajax in php. While passing values,i am getting below error  </p>
  
  <p><strong>Uncaught ReferenceError: $ is not defined</strong></p>
  
  <p>How to achieved this error i am new to php.</p>