title: How to get javascript value into php variable without reloading the page using ajax
body: <p>Here I want to get a value from <strong>JavaScript</strong> to <strong>PHP</strong> variable without using any POST or GET method.</p>
  <p>Here I'm giving HTML code:</p>
  <pre><code>&lt;input type=&quot;number&quot; name=&quot;days&quot; id=&quot;days&quot; class=&quot;col-sm-2 form-control&quot; placeholder=&quot;DAYS&quot;&gt; 
  
  &lt;input type=&quot;number&quot; name=&quot;night&quot; id=&quot;night&quot; class=&quot;col-sm-2 form-control&quot; placeholder=&quot;NIGHT&quot;&gt; 
                              
  &lt;button id=&quot;generate&quot; onclick=&quot;GetValue()&quot; class=&quot;btn btn-danger&quot;&gt;Generate&lt;/button&gt;
  </code></pre>
  <p>Javascript Code</p>
  <pre><code>&lt;script&gt;
  $(function(){
      $(&quot;#generate&quot;).on('click', function(){
          var days = $(&quot;#days&quot;).val();
          var night=$(&quot;#night&quot;).val();
          var base_url = $('#base').val();
          $.ajax({
          type: 'post',
          url: base_url,
          data: {'days' : days, 'night': night}, 
          success: function( data ) {
          console.log(data);
          }
        });
      });
    });
  &lt;/script&gt;
  </code></pre>
  <p>php code</p>
  <pre><code>&lt;?php
  $days = $_POST['days']; 
  $night = $_POST['night'];
  echo $days . &quot; &quot; . $night;
  ?&gt;
  </code></pre>
  <p>Variable value not working.</p>