duanmei4149 2016-04-11 15:41
浏览 44
已采纳

Joomla中带有ajax的500“内部服务器错误”

I'm using Ajax at front-end joomla site but unfortunately it doesn't run. Here is my code:

/components/com_prova/js/dashboard.js

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

/components/com_prova/controllers/ajaxraw.php

<?php
defined('_JEXEC') or die( 'Restricted access' );
jimport('joomla.application.component.controller');
jimport('functions.php');
class MycomponentControllerAjaxraw extends JController
{
     function updateReserve(){

     $booked = JRequest::getVar('reserved');
     $robotId = JRequest::getVar('robotId');

     $db_external=db_ext();

     $query = $db_external->getQuery(true);         
     $query = 'UPDATE robots SET booked='.$booked.' WHERE id='.$robotId;    

     $db_external->setQuery($query);
     $db_external->query();
}
}
?>

I get this error:

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

I have read different posts about that, but nothing works....help please!

UPDATE

function db_ext(){

$option = array(); 

$option['driver']   = 'mysql';            // Database driver name
$option['host']     = 'xxxxxx';                 // Database host name
$option['user']     = 'xxxxxxx';   // User for database authentication
$option['password'] = 'xxxxxxxx';     // Password for database authentication
$option['database'] = 'xxxxxxxxx';   // Database name
$option['prefix']   = '';                 // Database prefix (may be empty)
$db_external = &JDatabase::getInstance( $option );
return $db_external;
}

UPDATE DEBUG

If I go to

index.php?option=com_prova&task=ajaxraw.updateReserve&format=raw&robotId=2&reserved=1&lang=en

I have this error

Invalid controller: name='ajaxraw', format='raw'

Someone can help me?

  • 写回答

1条回答 默认 最新

  • douhao5280 2016-04-12 11:10
    关注

    The following code I've fixed up for you will not be the solid solution but will push you in the right direction as there's currently a lot wrong with your code as it stands:

    • Incorrect use of API
    • Deprecated functions
    • Incorrect approach for calling functions

    Comment out all your Ajax code and let's just try and get some results show just with PHP:

    class MycomponentControllerAjaxraw extends JController
    {
        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']     = 'xxx';
            $option['user']     = 'xxx';
            $option['password'] = 'xxx';
            $option['database'] = 'xxx';
            $option['prefix']   = '';
    
            $db = JDatabaseDriver::getInstance($option);
    
            return $db;
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。