PHP and javascript - Getting javascript value in PHP (session usage)

1

In the site that I assumed from another developer, made in PHP and Javascript, there is a search for created events (all registered in MySQL database table). In each event that I searched for, I created a button to delete it:

<input name="excluir" type="button" class="textDescricaoSobre font13" value="Excluir" onclick="excluiEvento(<?php echo $evento['id'];?>)" style="cursor: pointer; width: 55px; margin-left: 10px;" />

And the event exclusion function, in javascript:

function excluiEvento(val){
    var valor = val;
    location.href = "http://meusite/excluir/"+valor;
}

Since this link goes to the delete function, defined in my Controller file:

public function excluir(){
    class_exists('Servico') || include_once CLASS_PATH . 'Servico.class.php';

    echo "<script>alert('Evento ".$_POST['valor']." foi pego')</script>";
    self::consultaeventos();
}

Everything works fine, but the value of the javascript value variable is not displayed in the alert. How can I do this value? Use Session? Use $ _GET instead of $ _POST?

    
asked by anonymous 14.06.2016 / 15:59

1 answer

1

The problem is happening because you are passing the value in the url as a directory, rewrite the javascript function to:

function excluiEvento(val){
    var valor = val;
    location.href = "http://meusite/excluir/?valor="+valor;
}
                                    
14.06.2016 / 16:21