Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
joomla通过ajax执行php函数_Php_Ajax_Joomla - Fatal编程技术网

joomla通过ajax执行php函数

joomla通过ajax执行php函数,php,ajax,joomla,Php,Ajax,Joomla,我使用的是Joomla2.5,我想通过ajax执行一个php函数,在外部数据库中进行更新。 这是我的ajax调用: $.ajax({ url: "index.php?option=com_prova&format=raw&task=updateReserve", data: { robotId: idRobot, reserved: book} }).done(function(response) {

我使用的是Joomla2.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)
为什么?有什么问题?
谢谢

您查看了Chrome的网络选项卡中的响应了吗?我没有答案,只是提醒您Joomla 2.5已经过时了;在将近一年半的时间里,对它的支持结束了。您真的应该考虑升级到当前支持的版本,尤其是Joomla版本之间的前向兼容性非常好。@Spudley很遗憾,我无法升级到新版本。@Shaz Chrome的“网络”选项卡显示“状态500错误”在index.php?option=com_prova&format=raw&task=updateReserve&robotId=2&reserved=1&lang=I上,您是否检查了Chrome的网络选项卡中的响应?我没有答案,只是提醒您Joomla 2.5已经过时;在将近一年半的时间里,对它的支持结束了。您真的应该考虑升级到当前支持的版本,尤其是Joomla版本之间的前向兼容性非常好。@Spudley很遗憾,我无法升级到新版本。@Shaz Chrome的“网络”选项卡显示“状态500错误”在index.php上?option=com\u prova&format=raw&task=updateReserve&robotId=2&reserved=1&lang=it