title: Using POST via AJAX and PHP to send data
body: <p>I have an object I am sending in an AJAX request:</p>
  
  <pre><code> function send_value() {
      $.ajax({
          type: 'post',
          url: 'get.php',
          data: {
              source1: "some text",
              source2: "some text 2",
              uniId: 3
          },
          success: function (data) {
              console.log(data);
          }
      });
      return false;
  }
  </code></pre>
  
  <p>I am trying to post them on click of a button</p>
  
  <pre><code>&lt;head&gt;
      &lt;script src="./script.js"&gt;&lt;/script&gt;
      &lt;script src="//code.jquery.com/jquery-1.12.0.min.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form action="get.php" method='post' name='sendform' onSubmit='send_value()'&gt;
          &lt;input type='submit' value='Test1'&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>Then I print the variables using PHP:</p>
  
  <pre><code>&lt;?php
      if (!empty($_POST["uniId"])) 
      {
          if ($_POST["uniId"] == 3) 
          {
              echo 'your logged in as '; 
              echo $_POST['uniId'];
  
              $src1 = $_POST['source1'];
              $src2 = $_POST['source2'];
              echo $src1;
              echo $src2;
          } 
          else 
          {
              echo 'sorry uniID is not correct';
          }
      } 
      else 
      {
          echo "Im sorry the page was not able to load ";
          var_dump($_POST);
      }
  </code></pre>
  
  <p>Now the <code>uniID</code> is <code>3</code> so I hope to see:</p>
  
  <pre><code>your logged in as 3 some text some text2
  </code></pre>
  
  <p>But instead I get:</p>
  
  <pre><code>Im sorry the page was not able to load
  C:\wamp64\www\mysite\get.php:20:
  array (size=0)
  empty
  </code></pre>
  
  <p>What is wrong in my code that the variables are not being posted and printing out in my PHP?</p>
  
  <p>Thanks</p>