title: pass js variable to php using ajax on the same page
body: <p><strong>this is my html code:</strong></p>
  
  <pre><code>&lt;form id="form" action="javascript:void(0)"&gt;
  &lt;input type="submit" id="submit-reg" value="Register" class="submit button" onclick="showtemplate('anniversary')" style='font-family: georgia;font-size: 23px;font-weight: normal;color:white;margin-top:-3px;text-decoration: none;background-color: rgba(0, 0, 0, 0.53);'&gt;    
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>this is my javascript code:</strong></p>
  
  <pre><code>function showtemplate(temp)
  {
      $.ajax({
          type: "POST",
          url: 'ajax.php',
          data: "section="+temp ,
          success: function(data)
          {
              alert(data);
          }
      });  
  }  
  </code></pre>
  
  <p><strong>this is my ajax.php file:</strong></p>
  
  <pre><code>&lt;?php
  $ajax=$_POST['section'];
  echo $ajax;
  ?&gt;
  </code></pre>
  
  <p>The above html and javascript code is included in a file named slider.php. In my index file i have included this slider.php file and slider.php is inside slider folder. So basically index.php and slider.php are not inside the same folder.</p>
  
  <p>Javascript code alerts the data properly. But in my php code (ajax.php file) the value of $_POST['section'] is empty. What is the problem with my code. I tried googling everything and tried a few codes but it still doesn't work. Please help me out</p>