PHP and javascript - Getting javascript value in PHP (use of Session)

Asked

Viewed 412 times

1

On the site I took over from another developer, done in PHP and Javascript, there is a search for events created (all registered in Mysql database table). In each event searched, I created a button to be able 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 delete function, set 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 variable value is not displayed in the alert. How can I see this value? Session Usage? Use $_GET instead of $_POST?

1 answer

1


The problem is happening because Voce is passing the value in the url as a directory, rewriting the javascript function to:

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

added ?value= at the url

And php code instead of $_POST['value'] use $_GET['value']

Browser other questions tagged

You are not signed in. Login or sign up in order to post.