title: Call PHP Class Method From AJAX Request
body: <p>Iḿ trying to instantiate and execute a custom class method from AJAX, but returns a 500 Code Error, here's the ajax:</p>
  <p>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</p>
  <pre><code>function BorraEmple(TipoDocu,NumePers)
  {
      if(confirm(&quot;Eliminar Empleado (&quot;+TipoDocu+&quot; &quot;+NumePers+&quot;), Desea Continuar?&quot;))
      {
          var CodiDocu =$(&quot;#CmbCodiDocu&quot;).val();
          var NumeDocu =$(&quot;#TxtNumeDocu&quot;).val();
          $.ajax({
           type: 'POST',
           url: 'borraemple.php',
           data: &quot;Accion=BorraEmple&quot;+&quot;&amp;TipoDocu=&quot;+TipoDocu+&quot;&amp;NumePers=&quot;+NumePers+&quot;&amp;CodiDocu=&quot;+CodiDocu+&quot;&amp;NumeDocu=&quot;+NumeDocu,
           dataType: 'text',
           async: false,
           success: function(data)
           {
             setTimeout(function(){
             location.reload(); 
              }, 2000);
             if(/ErrorSQL/.test(data))
               alert(&quot;Error al consultar el registro, contacte a soporte tecnico&quot;);
             else
             {
                  if(data!='')
                      alert(data);
             }
             alert(&quot;El registro ha sido eliminado&quot;);
           },
           error: function(xhr, ajaxOptions, thrownError) {
          alert(xhr.status);
          alert(thrownError);
           }
         });
      }
  }
  </code></pre>
  <p>And here is the php:</p>
  <pre><code>&lt;?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-&gt;preserveWhiteSpace = true;
          $doc-&gt;load('NominaIndividualDeAjusteElectronicaXSDV1.0.xsd');
          $doc-&gt;save('a.xml');
          $xmlfile = file_get_contents('a.xml');
  
          $parseObj = str_replace($doc-&gt;lastChild-&gt;prefix.':',&quot;&quot;,$xmlfile); 
          $doc-&gt;doc-&gt;textContent;
  
          $ob= simplexml_load_string($parseObj);
                      $json  = json_encode($ob, JSON_PRETTY_PRINT);
                      $arrayNomiElect = json_decode($json, true);
  
          return $arrayNomiElect;
      }
  
      $sqlNumePers = &quot;SELECT CodiDocu, NumeDocu, CodiInst, CodiAno, CodiMes, TipoDocu, NumePers FROM DetaNomi WHERE CodiDocu='$CodiDocu' AND NumeDocu='$NumeDocu' AND NumePers=$NumePers GROUP BY TipoDocu,NumePers&quot;;
      $resNumePers = query($sqlNumePers,2);
      $ManeNoEl = parametros('ManeNoEl');
  
      foreach($resNumePers as $key =&gt; $value) {
  
        $datos = array(
          'CodiDocu'         =&gt; $value['CodiDocu'],
          'NumeDocu'         =&gt; $value['NumeDocu'],
          'CodiInst'         =&gt; $value['CodiInst'],
          'CodiAno'          =&gt; $value['CodiAno'],
          'CodiMes'          =&gt; $value['CodiMes'],
          'TipoDocu'         =&gt; $value['TipoDocu'],
          'NumePers'         =&gt; $value['NumePers'],
          'arraybase'         =&gt; getArray()
        );
  
        $sqlIns=&quot;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]')&quot;;
        //echo $sqlIns; exit();
        query($sqlIns);
  
        if($ManeNoEl == 1){
        $nominaElect = new NominaAjuste($datos);
        $nominaElect-&gt;getEstructura('E');
        }
      }
   }
   else
      $retorno='';
  
   echo $retorno;
  }
  </code></pre>
  <p>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..</p>
  <p>Thanks.</p>