Undefined offset: 0 i

0
  

Uncaught SyntaxError: Unexpected token < in JSON at position 0       at JSON.parse ()       at Object.success (: 392: 47)       at i (jquery.min.js: 2)       at Object.fireWith [as resolveWith] (jquery.min.js: 2)       at A (jquery.min.js: 4)       at XMLHttpRequest. (jquery.min.js: 4)

<?php
require_once("4_Utils/Utils.php");

class CapaDatos{
    public static $_db;
    public $_datos;

    public function __construct(){
        //si ya esta abierta la conexion no abrirla nuevamente
        if(!self::$_db ) {
                self::$_db=new mysqli("localhost", "root", "", "gestionelo");
                self::$_db->query("SET NAMES 'utf8'");
            }  
        public function execute_array($sqlGroup, $sqlName, $arrFiltros, $modo){
        if ( ! session_id() ) session_start();
        //Leer archivo donde se encuentran los SQL a ejecutar
        $strSQL = "";
                $xml= simplexml_load_file(__DIR__."\".$sqlGroup.".xml");
        $sqls = $xml->xpath("//SQL[@id='".$sqlName."']");
        $strSQL = $sqls[0]; 

                if ($strSQL =="" or $strSQL == null)
                {
                  utils_debugfile( "SQL No encontrado", $sqlGroup."-->".$sqlName);  
                };

                //Reemplazar variables globales del usuario
                if (isset($_SESSION['Email']))
                {
                    $strSQL = str_replace ( '@@Email' , $_SESSION['Email'], $strSQL );
                    $strSQL = str_replace ( '@@IdUserNet' , $_SESSION['IdUserNet'], $strSQL );
                    $strSQL = str_replace ( '@@IdEmpresa' , $_SESSION['IdEmpresa'], $strSQL );
                    $strSQL = str_replace ( '@@IdUsuario' , $_SESSION['IdUsuario'], $strSQL );
                    $strSQL = str_replace ( '@@Alias' , $_SESSION['Alias'], $strSQL );
                    $strSQL = str_replace ( '@@NivelAdmin' , $_SESSION['NivelAdmin'], $strSQL );
                }                

                //Reemplazar parámetros
        foreach ($arrFiltros as $variable)  //=> $valor
        {
                        utils_debugfile( "CapaDatosId", $variable->Id);
                        utils_debugfile( "CapaDatosValue", $variable->Value);
            //$strSQL = str_replace ( '@'.$variable , $valor_formateado, $strSQL );
                        $strSQL = str_replace ( '@'.$variable->Id , $variable->Value, $strSQL );
        };

                //log ultimo sql ejecutado
                utils_debugfile( "SQL traducido->", $strSQL);
$_resultado=array
            (
                "estado" => -1,
                "mensaje" => "(sin mensaje)",
                "detalle" => "",
                "info" => "",
                "datos" => array()
            );
            //Ejecutar SQL
        $consulta= self::$_db->query($strSQL);   
        if (!$consulta)
        {
             $_resultado["estado"] = 0;
             $_resultado["mensaje"] = "Error en la ejecución de la consulta ";
             $_resultado["detalle"] =  $strSQL;
             $_resultado["info"] =  "";
             $_resultado["datos"][] =  array();

        }
        else
        {
             $_resultado["estado"] = 1;
             $_resultado["mensaje"] = "Ok";
             $_resultado["detalle"] =  "";
             $_resultado["info"] =  "";
                         if ($modo == "Consulta")
                         {
                                        while($filas=$consulta->fetch_assoc())
                    {
                     $_resultado["datos"][] = $filas;
                    }
                         }
        }
    
asked by Kristian Espitia 24.10.2018 в 22:59
source

1 answer

0

You are making an ajax request from the front. jQuery is waiting to receive JSON.

The backend returns something that starts with < which is not a valid JSON. Most likely, it is an HTML-type response, such as an Error 500.

Check the Chrome Devtools (or Firefox) for the ajax request and its response. In this should be the error message.

    
answered by 25.10.2018 в 00:16