joomla通过ajax执行php函数

时间:2016-04-13 15:45:49

标签: php ajax joomla

我正在使用Joomla 2.5,我想通过ajax在外部数据库中执行更新来执行php函数。 这是我的ajax电话:

$.ajax({

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

在components / com_prova中,我有一个controller.php文件,其中包含:

 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']     = 'xxxxxxxxxxx';
            $option['user']     = 'xxxxxxxxxx';
            $option['password'] = 'xxxxxxxxxx';
            $option['database'] = 'xxxxxxxxx';
            $option['prefix']   = '';

            $db = JDatabaseDriver::getInstance($option);

            return $db;
        }

}

但所有这一切都行不通。我在控制台上有这个错误:

  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)

为什么?问题是什么? 感谢

0 个答案:

没有答案