title: Ajax change php variable
body: <p>I've got this variable <code>$type</code> and I want it to be <code>month</code> or <code>year</code>.
  It should be changed by pressing a <code>div</code>.</p>
  
  <p>I've tried creating an <code>onclick</code> event with an ajax call. </p>
  
  <p>The <code>ajax</code> call and the <code>variable</code> are in the same script (<code>index.php</code>) </p>
  
  <p>Inside the onclick function:</p>
  
  <pre><code>var curr_class = $(this).attr('class');
  
  
  $.ajax({
      type: "POST",
      url: "index.php",
      data: {
          type: curr_class
      },
      dataType: 'text',
      success: function(data) {
          // Test what is returned from the server
          alert(data);
      }
  });
  </code></pre>
  
  <p>But the alert returns the <em>whole</em> html page.
  When I console.log the data (create a <code>var data = { type:curr_class }) and console.log *that data* it returns</code>type = month` (which is correct) </p>
  
  <p>while I just want it to return <em>month</em> or <em>year</em> </p>
  
  <p>So on top of the page I can call</p>
  
  <pre><code>if(empty($_POST['type'])){
       $type = 'month';
  } else {
       $type = $_POST['type'];
  }
  </code></pre>
  
  <p>and change the PHP variable so I can use it in the rest of my script.</p>
  
  <p>But how can I accomplish this?</p>
  
  <p>With kind regards,</p>