Get value script Confirm and pass to PHP

1

Can you do this? Does the confirm data of a <script></script> go to the URL? To work in PHP using $_GET[""];

    
asked by anonymous 12.06.2017 / 22:57

1 answer

3

Yes!

You can do it in 2 ways, choose the one that best suits what you want:

Redirects to a PHP page by passing the Query String name

var nome = prompt("Informe seu nome");

window.location.href='arquivo.php?nome='+nome;

Sending via Ajax

jQuery:

var nome = prompt("Informe seu nome");

$.ajax({
    url: 'arquivo.php',
    type: 'GET',
    data: {nome: nome},

    success: function(resposta){

        alert(resposta);
    }
});

Getting the data passed in the URL:

<?php
echo 'O nome informado é '.$_GET['nome'];
?>
    
12.06.2017 / 23:09