1

Iḿ trying to instantiate and execute a custom class method from AJAX, but returns a 500 Code Error, here's the ajax:

I want that the ajax call create an array from a given xml, this is working as expected, after that I need to create an array from an SQL query and execute an Insert Statement, and with the data from the SQL array I have to call a class method, Iḿ making the includes but that doesnt working

function BorraEmple(TipoDocu,NumePers)
{
    if(confirm("Eliminar Empleado ("+TipoDocu+" "+NumePers+"), Desea Continuar?"))
    {
        var CodiDocu =$("#CmbCodiDocu").val();
        var NumeDocu =$("#TxtNumeDocu").val();
        $.ajax({
         type: 'POST',
         url: 'borraemple.php',
         data: "Accion=BorraEmple"+"&TipoDocu="+TipoDocu+"&NumePers="+NumePers+"&CodiDocu="+CodiDocu+"&NumeDocu="+NumeDocu,
         dataType: 'text',
         async: false,
         success: function(data)
         {
           setTimeout(function(){
           location.reload(); 
            }, 2000);
           if(/ErrorSQL/.test(data))
             alert("Error al consultar el registro, contacte a soporte tecnico");
           else
           {
                if(data!='')
                    alert(data);
           }
           alert("El registro ha sido eliminado");
         },
         error: function(xhr, ajaxOptions, thrownError) {
        alert(xhr.status);
        alert(thrownError);
         }
       });
    }
}

And here is the php:

<?php
include_once(SIH_PATH.'clases/FES/nominajuste.class.php');
if($_POST[Accion]=='BorraEmple'){
    $TipoDocu=$_POST[TipoDocu];
    $NumePers=$_POST[NumePers];
    $CodiDocu=$_POST[CodiDocu];
    $NumeDocu=$_POST[NumeDocu];

if(strlen($MesInve)==1)
  $MesInve2='0'.$MesInve;
else
  $MesInve2=$MesInve;
 $DocuApli=docuapli($CodiDocu);
 $Cond='';
 if($DocuApli==124){
  $EnviNomi = parametros('EnviNomi', 2);
  if($EnviNomi==1){
    function getArray(){
        $doc = new DOMDocument();
        $doc->preserveWhiteSpace = true;
        $doc->load('NominaIndividualDeAjusteElectronicaXSDV1.0.xsd');
        $doc->save('a.xml');
        $xmlfile = file_get_contents('a.xml');

        $parseObj = str_replace($doc->lastChild->prefix.':',"",$xmlfile); 
        $doc->doc->textContent;

        $ob= simplexml_load_string($parseObj);
                    $json  = json_encode($ob, JSON_PRETTY_PRINT);
                    $arrayNomiElect = json_decode($json, true);

        return $arrayNomiElect;
    }

    $sqlNumePers = "SELECT CodiDocu, NumeDocu, CodiInst, CodiAno, CodiMes, TipoDocu, NumePers FROM DetaNomi WHERE CodiDocu='$CodiDocu' AND NumeDocu='$NumeDocu' AND NumePers=$NumePers GROUP BY TipoDocu,NumePers";
    $resNumePers = query($sqlNumePers,2);
    $ManeNoEl = parametros('ManeNoEl');

    foreach($resNumePers as $key => $value) {

      $datos = array(
        'CodiDocu'         => $value['CodiDocu'],
        'NumeDocu'         => $value['NumeDocu'],
        'CodiInst'         => $value['CodiInst'],
        'CodiAno'          => $value['CodiAno'],
        'CodiMes'          => $value['CodiMes'],
        'TipoDocu'         => $value['TipoDocu'],
        'NumePers'         => $value['NumePers'],
        'arraybase'         => getArray()
      );

      $sqlIns="INSERT INTO NomiElec (CodiDocu, NumeDocu, CodiInst, CodiAno, CodiMes, TipoDocu, NumePers) VALUES ('$datos[CodiDocu]','$datos[NumeDocu]','$datos[CodiInst]','$datos[CodiAno]','$datos[CodiMes]','$datos[TipoDocu]','$datos[NumePers]')";
      //echo $sqlIns; exit();
      query($sqlIns);

      if($ManeNoEl == 1){
      $nominaElect = new NominaAjuste($datos);
      $nominaElect->getEstructura('E');
      }
    }
 }
 else
    $retorno='';

 echo $retorno;
}

I have tested the functions without ajax and everything works as supossed, I'm not very familiar with ajax, and don't know if I'm doing well..

Thanks.

  • pls show full error message – Maksim Jul 21 '21 at 22:20
  • Ajax returns a 500 error- – Rafael Granados Jul 21 '21 at 22:27
  • it's error code - I request an error message. – Maksim Jul 21 '21 at 22:31
  • Internal server error.. – Rafael Granados Jul 21 '21 at 23:02
  • Set [PHP error reporting to loud](https://stackoverflow.com/a/21429652/231316), post the _specific error message_, including line number, and also show us what the line number represents in your code. Further, for your debugging purposes, jQuery is just a wrapper around JavaScript, AJAX is a wrapper around a browser request, and POST is just a complicated GET. Try removing AJAX and jQuery, and switching over to just a GET request that you can debug. When that starts working, add complexities back in. – Chris Haas Jul 22 '21 at 03:20
  • Thanks. I'm actually debugging my code but I'm seeing that POST is working properly, the error happens when I try to access to my custom class method, I don't know why this error happen, the includes are Ok so can't find the error.. – Rafael Granados Jul 26 '21 at 13:12

0 Answers0