0

I have a page where I do different requests via AJAX, also I have the developer DB and the production DB but the JS is the same. In certain module, if I open it using the developer DB it shows me the response but if I use the production database it shows nothing but not error is displayed. If I use the production DB in any other module it works perfectly. I already checked in the network console and it says that in both cases the request is sent. Here is the JS code:

function consultaAdministradores(id, tipo, btn){

var datos = {

    'id': id,

    'tipo': tipo

  }

  console.log("DATOSSSS");
  console.log(datos);

$.ajax({

  url: '../send/get_AdminEmpresas.php',

  type: 'POST',

  data: datos,

  dataType: 'JSON',

  success: function(res) {
    console.log(" res --------- ");
    console.log(res);
    imprimeAdmins(res);

  }

});

console.log("Se pasó el AJAX");

And in the PHP file I have this:

  $res = $con->consulta($sql);
  if ($res->num_rows > 0 ) {

    $i = 0;
    while ($dato = $res->fetch_assoc()) {
        $administradores[$i] = $dato;
            $i++;
    }
    if ($tipo_page == 'prev') {
     array_multisort($administradores);
    }
    $array = array('status' => "Success", 'administradores' => $administradores, 'id' => $id_page, 'tipo' => $tipo_page);
  }
  else
  {
    $array = array('status' => "Fail", 'message' => 'Sin resultados');
  }

  $json = json_encode($array);
  echo $json;
Mehran
  • 282
  • 1
  • 6
  • 17
  • Where is it switching between developer and production DB? – Barmar Dec 05 '18 at 19:58
  • In another file, I have a case where I validate if I'm using dev or prod DB. – Alejandro Paredes Dec 05 '18 at 20:13
  • Make sure you have error checking and reporting in the `consulta()` method. See https://stackoverflow.com/questions/22662488/how-to-get-mysqli-error-in-different-environments for how to get mysqli errors. – Barmar Dec 05 '18 at 20:20

1 Answers1

-1

The problem wasn't the JS or the PHP files, the problem was the codification of the DB, I inserted some data in UTF-8 codification and later I converted to UTF-8 codification giving me as a result some weird characters.