PHP $_SERVER['REQUEST_METHOD'] always returning GET with AJAX post
<p>I am trying to set up an api for my website. I would like to have a single page that does a different action depending on the request method. ie. GET to get a resource, POST to create a new one, PUT to update and DELETE to delete. I am testing the <code>$_SERVER['REQUEST_METHOD']</code> variable to see which function I should run but for some reason it is always showing as get regardless of my ajax request.</p>

<p><strong>Page 1</strong></p>

<pre><code>var data = {
            store_id: id,
            reward: reward,
            disclaimer: disclaimer,
            period: period,
            active: active
        }

        //make request to save item
        $.ajax({
                type: "POST",
                url: 'http://' + '&lt;?php echo $base_url; ?&gt;' + 'api/birthday',
                data: data,
                dataType: 'json',
                //headers: {"X-HTTP-Method-Override": "POST"},
                success: function(obj){
                    console.log(obj);
                    $('#save-modal').dialog('open');
                },
                error: function(xhr, textStatus, errorThrown){
                    console.log(arguments);
                    console.log(xhr + '' + textStatus + ' ' + errorThrown);
                }
        });
</code></pre>

<p><strong>Page 2</strong></p>

<pre><code>if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if( isset($_REQUEST['store_id']) &amp;&amp;
        isset($_REQUEST['reward']) &amp;&amp;
        isset($_REQUEST['disclaimer']) &amp;&amp;
        isset($_REQUEST['period']) &amp;&amp;
        isset($_REQUEST['active']) &amp;&amp;
        is_numeric($_REQUEST['active'])){
            exit(json_encode(update_birthday_reward(filter_var($_REQUEST['store_id'], FILTER_SANITIZE_NUMBER_INT), filter_var($_REQUEST['reward'], FILTER_SANITIZE_STRING), filter_var($_REQUEST['disclaimer'], FILTER_SANITIZE_STRING), filter_var($_REQUEST['period'], FILTER_SANITIZE_STRING), filter_var($_REQUEST['active'], FILTER_SANITIZE_NUMBER_INT))));   
    }else{
        exit(json_encode($_SERVER['REQUEST_METHOD']));
    }
}else if ($_SERVER['REQUEST_METHOD'] === 'GET') {
    if(isset($_REQUEST['store_id'])){
        exit(json_encode(get_birthday_reward($_REQUEST['store_id'])));  
    }else{
        exit(json_encode($_SERVER['REQUEST_METHOD']));
    }
}
</code></pre>