Back to top

Autore Topic: joomla eseguire codice php via ajax  (Letto 2171 volte)

Offline lucatr

  • Nuovo arrivato
  • *
  • Post: 1
    • Mostra profilo
joomla eseguire codice php via ajax
« il: 14 Apr 2016, 17:54:25 »
Ciao, ho creato un nuovo componente in Joomla (2.5) e vorrei gestire le richieste in ajax. Vorrei eseguire un file php via ajax che fa un aggiornamento su un database esterno. Questa è la chiamata ajax:


Codice: [Seleziona]
$.ajax({
         
            url: "index.php?option=com_prova&task=updateReserve&format=raw",
         data: { robotId: idRobot, reserved: book}
              }).done(function(response) {
              console.log(response);
        }); 

In components/com_prova ho il file controller.php che contiene:

Codice: [Seleziona]
class ProvaController extends JController
{
   /**
    * Method to display a view.
    *
    * @param   boolean  $cachable   If true, the view output will be cached
    * @param   mixed    $urlparams  An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
    *
    * @return   JController        This object to support chaining.
    *
    * @since    1.5
    */
   public function display($cachable = false, $urlparams = false)
   {
     
     
         
      parent::display($cachable, $urlparams);


      return $this;
   }
   
   
   
   public function updateReserve(){


         
         
         $input = JFactory::getApplication()->input;
         $booked  = $input->get('reserved', '', 'INT');
         $robotId = $input->get('robotId', '', 'INT');
         $db = $this->external_db();
         $query = $db->getQuery(true);
         $fields = array(
         $db->quoteName('booked') . ' = ' . (int)$booked
         );
         $conditions = array(
             $db->quoteName('id') . ' = ' . (int)$robotId);
         $query->update($db->quoteName('robots'))->set($fields)->where($conditions);
         $db->setQuery($query);
         $result = $db->execute();


         
 
         
     
         }
         
         private function external_db()
         {
            $option = array();
     
            $option['driver']   = 'mysql';
            $option['host']     = 'xxxx';
            $option['user']     = 'xxxx';
            $option['password'] = 'xxxx';
            $option['database'] = 'xxxx';
            $option['prefix']   = '';
     
            $db = JDatabaseDriver::getInstance($option);
     
            return $db;
         }
   
}

Ma non funzione. In console ho questo errore:

Codice: [Seleziona]
jquery-1.12.3.min.js:4 GET http://xxxxxx/xxxxxxx/index.php?option=com_prova&format=raw&task=updateReserve&robotId=2&reserved=1&lang=it 500 (Internal Server Error)


Aiutatemi! Grazie!

 



Web Design Bolzano Kreatif