0

so I have a php file that brings information from a database about an user. My idea is that when an button is pressed I send the id to the php file and the get the user that corresponds. However I can't seem to execute the php file, and the ajax response is empty.

How can I fix this? Thank you for your help

EDIT: I removed the die function, and add the echo the $usuario array. Now i get it in the response but i have a dumb question: how do i access the data of that array? Thank you again

2 Answers2

0
<?php
 require_once 'constantes.php';
 require_once 'smarty.php';
 require_once 'verificar_rol.php';

 $nro = $_GET['nro'];
try{
   $mysqli = new mysqli(HOST,USUARIO,PASSWORD,DB);
   if($mysqli->connect_errno){
      throw new Exception("Error al conectarse a servidor Mysql");
   }
  $sql = "SELECT * FROM persona WHERE nro = $nro";
   // here is some change
  $resultado = $mysqli->query($sql)  
  if(!$resultado){
  // end change
    throw new Exception("Error al obtener los datos");
  }
  $usuario = $resultado->fetch_assoc();
  echo $usuario;

}catch(Exception $excepcion){
  $smarty->assign("error", 1);
  $smarty->assign("mensaje", $excepcion->getMessage());
 }

and this

$("#editar").click(function(){
    var nro = $(this).data('id');
    $.ajax({
        url: "editar_persona.php",
        type: 'GET',
        data: {nro: nro},
    }).done(function(response){
        console.log(response);
        alert(response);
    });

Try this

-1

What about

$("#editar").click(function(){
    var nro = $(this).data('id');
    $.ajax({
        url: "editar_persona.php?nro="+nro,
        type: 'GET'
    }).done(function(response){
        console.log(response);
        alert(response);
    });

GET request uses URL to pass Data