dongyou8368 2016-04-13 15:45
浏览 43

joomla通过ajax执行php函数

I'm using Joomla 2.5 and I want to execute a php function via ajax that do an update in an external database. This is my ajax call:

$.ajax({

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

In components/com_prova I have a controller.php file that contains:

 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;
        }

}

But all of this does not work. I have this error on console:

  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)

Why?What is the problem? Thanks

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 程序不包含适用于入口点的静态Main方法
    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记