Pick up value script Confirm and move to PHP

Asked

Viewed 404 times

1

Do you have how to do that? A confirm data <script></script> go to URL? To work in PHP using $_GET[""];

  • For the same current PHP or AJAX ?

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);
    }
});

Picking up data passed in URL:

<?php
echo 'O nome informado é '.$_GET['nome'];
?>
  • With Ajax did not give no, did not send the information pa URL

Browser other questions tagged

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