Upload information from a JS to PHP

0

I need to get information from a JS file (form.js) and load it into a PHP file (mail.php).

In the form.js file there is a function that calculates the delivery value based on the zip codes. Here is her variable:

var taxadeentrega = total - taxa;

Here is a snippet of code for your understanding:

//aqui eu pego o cep
var cep = document.getElementById("cep").value;

//verifica se deve incrementar ou não
if(cep == "20010-090" || cep == "20020-100" || cep == "20021-130" || cep == "20021-315" || cep == "20030-901" || cep == "20030-021" || cep == "20210-030" || cep == "24220-280"){               
    //se for um dos ceps acima, incrementa 1.2 no valor final
    taxa = 1.50;            
}
if(cep == "20020-010"|| cep == "22050-032" || cep == "20020-040" || cep == "20020-080" || cep == "20030-905" || cep == "24220-031" || cep == "20002-010" || cep == "20030-015"){
    //se for um dos ceps acima, incrementa 0.7 no valor final
    taxa = 1.00;            
}

total += taxa;

if(taxa != 0){
    //caso a taxa seja diferente de 0, mostra ao usuário
    document.getElementById("idTaxa").innerHTML = "Custo adicional: R$ " + taxa;
}

This is the delivery value, I need this information to be loaded into my mail.php file where it now pulls directly from the form field like this:

$entrega = $_POST["taxadeentrega"];

I need this information correctly to apply to another rule. That is, summarizing: I need $entrega = VALOR_DA_TAXA to be pulling form.js file

    
asked by anonymous 30.08.2017 / 22:33

1 answer

0

You could send the form via post, but if you want to handle JS and PHP directly, you can use AJAX , below an example with jQuery:

$.post("mail.php", {taxadeentrega: taxa})
.done(function(data){
    // CASO TENHA CONCLUIDO
    console.log(data);
})
.fail(function(data){
    // CASO TENHA FALHADO
});

PS: If you're going to use pure Javascript, visit this reference .

    
30.08.2017 / 23:09