I want to show the result of an AJAX query in different parts of my website. That is, in my query I have two echo
within the PHP that I want to print in my HTML document.
The problem is that he shows them both together. For example:
NOMBRE: //aqui que me muestre el nombre de mi variable nombre en php
EDAD: //aqui que me muestre la edad de mi variable edad en php
but at the time of making the query, he gives me the following example:
NOMBRE:andy 18 //nombre y edad juntos
EDAD:andy 18 //nombre y edad juntos
Here is an example of the code:
$(document).ready(function () {
$(".info").click(function(e){
var nombre=$("#nombre").val();
var edad=$("#edad").val();
$("#formulario").submit(function(e){
e.preventDefault();
$.ajax({
url:"info.php",
type:"POST",
dataType: 'json',
data:${nombre:nombre,edad:edad},
beforesend:function(){
$("#resultados").html("<img src='img/loading.gif'>");
},
success:function(data){
$("#resultados1").html(data); //aqui un div para mostrar el nombre
$("#resultados2").html(data);//aqui un div para mostrar la edad
}
});
});
});
});
PHP Code:
<?php
//esto viene de dos input
$nombre=$_POST['nombre'];
$edad=$_POST['edad'];
echo $nombre;
echo $edad;
?>