Cookies disappearing after refresh in Cakephp 3

here is my HTML:

<a class="dropdown-item" value="1">Try1</a>
<a class="dropdown-item" value="2">Try2</a>
<a class="dropdown-item" value="3">Try3</a>

Lets have a look of my jQuery and ajax:

<script type="text/javascript">

$(document).ready(function() {

    $(".dropdown-item").click(function(){
         idString = $(this).attr("value");
        alert(idString);
        $.ajax({
            type: "POST",
            url: "<?php echo  \Cake\Routing\Router::url(array('controller' => 'MyController', 'action' => 'index')); ?>",
            data: "idString="+idString,
            success: function(result){

                $("#show").html(result);

            }
        });

    });

});

Now lets see MyController:

$jqeryanimalid = $this->request->getdata('idString');

    $this->Cookie->write('animalid', $jqeryanimalid,(time()+3600*24)+(mktime(24,0,0)-time()));
    $cookie_animalid = $this->Cookie->read('animalid');

        $posts = $this->Posts->find('all', array(
            'conditions' => array(
                'Animal_id' => $cookie_animalid
            )
        ));
    $this->set(compact('posts'));

The returning value is what i want and it save the Cookies like Name:animalid and Value:1 if i click Try1. The big Problem is that after refreshing all its gone also in cookies and the value that i want to have! Why? Can someone help me?