As the title says, I have a webapp in PHP (not made by me), it works properly mounted on a local server (in XAMPP), the problem is that when I upload it to the live server a section and other things leave to work or not show as they should, I already made several tests and note that the specific section that shows nothing, this does not return JSON response and I think I have two possible culprits,
Check the code several times and I think it is correctly written (it is very basic PHP), there is no fault between the connection of the Bd with the system either, so I do not know exactly what is preventing the server show the information correctly, attach photos of what should show me and this is the part of the code that I think is the culprit that the requests are not made correctly.
function llenarNivel (idUsuario) {
$('#loadingIcon').show();
$.ajax({
url:'../controller/persona.php',
data: {'get':'buscarGenealogiaPorIdUsuario', 'datos':idUsuario},
type: 'POST',
dataType: 'json',
success: function(result){
if(result.opStatus == "error"){
console.log({"msg" : "error", "data" : result});
$('#car_container').html("");
$('#loadingIcon').hide();
} else {
var elements = "";
for(var i = 0; i < result.length; i++){
var imgFile = "";
if(result[i].FotoPerfil && result[i].FotoPerfil != "default.png"){
imgFile = "../core/files/profiles/"+ pad(result[i].IdUsuario,5) +"/images/" + result[i].FotoPerfil;
} else {
result[i].FotoPerfil = "default.png";
var imgFile = "../core/files/profiles/images/" + result[i].FotoPerfil;
}
elements += "<div onClick='itemClick(this);' class='item img_level div-square2' idUsuario='"+
result[i].IdUsuario + "' id='"+
result[i].IdUsuario + "'>"+
"<span style=\"background: url('"+ imgFile +"') no-repeat center; background-size: contain; display: inline-block;\" class='col-lg-4 col-md-4 col-sm-4 col-xs-4'> </span>" +
"<p class='col-lg-12 col-md-12 col-sm-12 col-xs-12'><span class='col-lg-12 col-md-12 col-sm-12 col-xs-12'>Nombre: " +
result[i].NombreCompleto +"</span> <span class='col-lg-12 col-md-12 col-sm-12 col-xs-12'>Plaza: "+
result[i].Ciudad + "</span> <span class='col-lg-12 col-md-12 col-sm-12 col-xs-12'>Correo: " +
result[i].Correo + "</span> <span class='col-lg-12 col-md-12 col-sm-12 col-xs-12'>Contacto: " +
((!result[i].Telefono) ? result[i].Celular : result[i].Telefono) + "</span></p></div>";
}
$('#car_container').html("<div class='owl-carousel'>" + elements + "</div>");
$(".owl-carousel").owlCarousel({
responsive: {
0: {
items: 1
},
800: {
items: 2
},
1024: {
items: 4
}
}
});
$('#loadingIcon').hide();
}
},
error: function(result){
console.log(result);
}
});
}
I uploaded a copy in case you want to do tests link
#TRAE LA INFO DEL ARBOL GENEALOGICO DE CADA USUARIO
public function buscarGenealogiaPorIdUsuario($datos) {
$idUsuario = $datos;
$qry = "SELECT
u.Id AS IdUsuario,
u.NumeroPatrocinador AS ReferenciaPatrocinador,
u.Posicion AS Posicion,
CONCAT(
p.Nombres, ' ',
p.ApellidoPaterno, ' ',
p.ApellidoMaterno) AS NombreCompleto,
p.CorreoElectronico AS Correo,
p.Telefono AS Telefono,
c.Nombre AS Ciudad,
p.Celular AS Celular,
t.Nombre AS TipoSuscripcion,
i.Nombre AS FotoPerfil
FROM usuario u
INNER JOIN tipo t ON u.IdTipoAfiliacion = t.Id
INNER JOIN persona p ON u.IdPersona = p.Id
INNER JOIN direccion d ON d.IdPersona = p.Id
INNER JOIN ciudad c ON c.Id = d.IdCiudad
LEFT OUTER JOIN expediente i ON i.IdUsuario = u.Id AND i.IdTipoDocumento = 5
WHERE u.IdPatrocinador = $idUsuario AND u.Id NOT IN($idUsuario)";
$l = new DataLink();
$r = $l->runQuery($qry, "SELECT");
return $r;
}
function buscarGenealogiaPorIdUsuario($datos){
$genealogia = array();
$p = new Persona();
$r = $p->buscarGenealogiaPorIdUsuario($datos);
if($r){
if($r->num_rows > 0){
while($gen = $r->fetch_assoc()){
if(!FILE_EXISTS('../core/files/profiles/'.STR_PAD($gen['IdUsuario'],5,"0",STR_PAD_LEFT).'/images/imgPerf'.STR_PAD($gen['IdUsuario'],5,"0",STR_PAD_LEFT).".png")){
$gen['FotoPerfil'] = 'default.png';
}
$genealogia[] = $gen;
}
}
return $genealogia;
}
}
case "buscarGenealogiaPorIdUsuario":
$genealogia = array();
$r = buscarGenealogiaPorIdUsuario($datos);
if($r){
$genealogia = $r;
echo JSON_ENCODE($genealogia);
} else {
echo JSON_ENCODE(array("opStatus"=>"error", "message"=>"hubo un error al realizar la consulta."));
}
unset($_POST['get']);
break;
case "consultarPersonaPorIdUsuario":
$persona = array();
$r = consultarPersonaPorIdUsuario($datos);
if($r){
$persona = $r;
echo JSON_ENCODE($persona);
} else {
echo JSON_ENCODE(array("opStatus"=>"error", "message"=>"hubo un error al realizar la consulta."));
}
unset($_POST['get']);
break;
JAVASCRIPT
<script>
$(document).ready(function(){
var idUsuario = getCookie('i');
llenarPatrocinador(idUsuario);
llenarNivel(idUsuario);
});
function llenarPatrocinador(idUsuario){
var idPadre = getCookie('i');
$.ajax({
url:'../controller/persona.php',
data: {'get':'consultarPersonaPorIdUsuario', 'datos':{'IdUsuario':idUsuario}},
type: 'POST',
dataType: 'json',
success: function(result) {
if(result.opStatus == "error") {
} else {
if(result.Imagen){
$('#img_headLevel')
.css("background","url('../core/files/profiles/"+result.preFile+"/images/"+result.Imagen+"') no-repeat center")
.css("background-size","contain");
$('#btn_back').attr("IdPadre",idPadre);
} else {
$('#img_headLevel')
.css("background","url('../core/files/profiles/images/default.png') no-repeat center")
.css("background-size","contain");
$('#btn_back').attr("IdPadre",idPadre);
}
}
},
error: function(result){
console.log(result);
}
});
}
function llenarNivel(idUsuario){
$('#loadingIcon').show();
$.ajax({
url:'../controller/persona.php',
data: {'get':'buscarGenealogiaPorIdUsuario', 'datos':idUsuario},
type: 'POST',
dataType: 'json',
success: function(result){
if(result.opStatus == "error"){
console.log({"msg" : "error", "data" : result});
$('#car_container').html("");
$('#loadingIcon').hide();
} else {
var elements = "";
for(var i = 0; i < result.length; i++){
var imgFile = "";
if(result[i].FotoPerfil && result[i].FotoPerfil != "default.png"){
imgFile = "../core/files/profiles/"+ pad(result[i].IdUsuario,5) +"/images/" + result[i].FotoPerfil;
} else {
result[i].FotoPerfil = "default.png";
var imgFile = "../core/files/profiles/images/" + result[i].FotoPerfil;
}
elements += "<div onClick='itemClick(this);' class='item img_level div-square2' idUsuario='"+
result[i].IdUsuario + "' id='"+
result[i].IdUsuario + "'>"+
"<span style=\"background: url('"+ imgFile +"') no-repeat center; background-size: contain; display: inline-block;\" class='col-lg-4 col-md-4 col-sm-4 col-xs-4'> </span>" +
"<p class='col-lg-12 col-md-12 col-sm-12 col-xs-12'><span class='col-lg-12 col-md-12 col-sm-12 col-xs-12'>Nombre: " +
result[i].NombreCompleto +"</span> <span class='col-lg-12 col-md-12 col-sm-12 col-xs-12'>Plaza: "+
result[i].Ciudad + "</span> <span class='col-lg-12 col-md-12 col-sm-12 col-xs-12'>Correo: " +
result[i].Correo + "</span> <span class='col-lg-12 col-md-12 col-sm-12 col-xs-12'>Contacto: " +
((!result[i].Telefono) ? result[i].Celular : result[i].Telefono) + "</span></p></div>";
}
$('#car_container').html("<div class='owl-carousel'>" + elements + "</div>");
$(".owl-carousel").owlCarousel({
responsive: {
0: {
items: 1
},
800: {
items: 2
},
1024: {
items: 4
}
}
});
$('#loadingIcon').hide();
}
},
error: function(result){
console.log(result);
}
});
}
function pad(num, size) {
var s = "00000" + num;
return s.substr(s.length-size);
}
function itemClick(item){
var idUsuario = item.id;
llenarPatrocinador(idUsuario);
llenarNivel(idUsuario);
$('#btn_back').show('fade');
}
$('#btn_back').click(function(){
var idUsuario = $(this).attr("IdPadre");
llenarPatrocinador(idUsuario);
llenarNivel(idUsuario);
$('#btn_back').hide('fade');
});
$('#car_left').click(function(){
$('.owl-carousel').trigger('prev.owl.carousel');
});
$('#car_right').click(function(){
$('.owl-carousel').trigger('next.owl.carousel');
});
</script>