</head>
<body>
<form action="llega.php" method="post">
<input type="text" name="fecha" id="fecha">
<input type="text" name="direccion" id="direccion">
<input type="submit" name="enviar">
<button id="enviar"><a href="llega.php">Enviar</button>
</form>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script type="text/javascript" src="envia.js"></script>
</body>
</html>
Through ajax we send the variables
$("#enviar").click(function(){
fecha =$("#fecha").val();
direccion =$("#direccion").val();
console.log(fecha,direccion);
var datos = new FormData();
datos.append("fecha", fecha);
datos.append("direccion",direccion );
$.ajax({
url:"llega.php",
type: "POST",
data: datos,
cache: false,
contentType: false,
processData: false,
success: function(respuesta){
}
});
});
The variables get to arrive.php but they don't get there any idea how to pass them without using a get method
<?php
echo $_POST["direccion"];
echo $_POST["fecha"];
?>
If you are going to use ajax indicating the URL, in the HTML form you do not need to put the
action
, it can create a conflict. And another thing, because you have an input typesubmit
and then a button that calls the pagetodollega.php
. Remove the button and keep the submit:The form is not necessary, because it could cause a conflict with the ajax, as well as the input submit and the href are unnecessary, just this would help you:
another thing you should adjust is the ajax:
And with that, the PHP you have collects the ajax variables.
You must remove the form tag:
Ajax would look like this:
You must create a file called process.php and in it write this code:
And in the file arrives.php you put:
I hope it helps you, greetings