Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.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 plugin 3.0中对依赖组合框的Ajax调用_Ajax_Joomla - Fatal编程技术网

joomla plugin 3.0中对依赖组合框的Ajax调用

joomla plugin 3.0中对依赖组合框的Ajax调用,ajax,joomla,Ajax,Joomla,我正在尝试在joomla插件中使用ajax调用。在插件中,有两个组合框:项目级别1和项目级别2。项目级别2依赖于项目级别1,并根据项目级别1的选择从MySQL表中加载(表bda_level_2)。表bda_level_2包含一个字段level1_id,它是表bda_level_1(项目级别1)的外键。项目级别1也从MySQL表(表bda_level_1)填充 ajax调用是一个POST请求,在数据字段中包含项目级别1 id:一个名为l1_id的参数。不知为什么,用于填充第二个组合框的ajax调用

我正在尝试在joomla插件中使用ajax调用。在插件中,有两个组合框:项目级别1和项目级别2。项目级别2依赖于项目级别1,并根据项目级别1的选择从MySQL表中加载(表bda_level_2)。表bda_level_2包含一个字段level1_id,它是表bda_level_1(项目级别1)的外键。项目级别1也从MySQL表(表bda_level_1)填充

ajax调用是一个POST请求,在数据字段中包含项目级别1 id:一个名为l1_id的参数。不知为什么,用于填充第二个组合框的ajax调用似乎失败了。我不知道这是与请求的格式有关,还是与从请求中检索参数有关,因为无法获取问题的日志记录。 以下是temp/default.php文件的代码:

<?php defined('_JEXEC') or die;

?>
<form>

        Project level 1:
        <select name="level1" class="level1">
        <option selected="selected">--Select Level 1--</option>
        <?php

        // Get a db connection.
        $db = JFactory::getDbo();

        // Create a new query object.
        $query = $db->getQuery(true);

        // Select records
        $query->select($db->quoteName(array('id', 'level1')));
        $query->from($db->quoteName('bda_level_1'));
        $query->order('level1 ASC');


        // Reset the query using our newly populated query object. 


        $db->setQuery($query);

        if($rows = $db->loadAssocList()){

          foreach($rows as $row){

            $level1_id=$row['id'];
            $data=$row['level1'];

            echo '<option value="'.$level1_id.'">'.$data.'</option>';
          }
        }

        ?>
        </select> 


        <br/><br/>

        Level 2:

        <select name="level2" class="level2">

        <option selected="selected">--Select Level 2--</option>

        </select>


</form>

非常感谢您的帮助。

我实际上指的不是joomla插件,而是joomla模块。我还尝试了以下请求:var request={'option':'com\u ajax','module':'project\u level\u ajax','data':value',format':'raw'};它给出了相同的结果该模块通过命令{loadmodule project\u level\u ajax}加载到文章中。这样,组合框在前端可见。joomla版本实际上是3.4,而不是3.0。所以,它应该在3.x中工作。
<?php defined('_JEXEC') or die;

class modProjectLevelAjaxHelper
{
    public static function getAjax()
    {
        $result = ""; 

        $input = JFactory::getApplication()->input;
        $id  = $input->post->get('data');

        $db = JFactory::getDbo();
        // Create a new query object.

        $query = $db->getQuery(true);
        $conditions = array(
            $db->quoteName('level1_id') . ' = ' . $db->quote($id));

        // Select records
        $query->select($db->quoteName(array('id', 'level2')));
        $query->from($db->quoteName('bda_level_2'));
        $query->where($conditions);
        $query->order('level2 ASC');

        // Reset the query using our newly populated query object. 
        $db->setQuery($query);

        if($rows = $db->loadAssocList()){

        foreach($rows as $row){

          $level2_id=$row['id'];
          $data=$row['level2'];

          $result += '<option value="'.$level2_id.'">'.$data.'</option>';

          }
        }
        return $result;
    }
}
<?php defined('_JEXEC') or die;

// Include the helper.
require_once __DIR__ . '/helper.php';

// Instantiate global document object
$doc = JFactory::getDocument();

$js = <<<JS
(function ($) {
    $('.level1').change(function () {
                var value   = $('.level1').val();
                var dataString = 'l1_id='+value;
                var request = {
                    'option' : 'com_ajax',
                    'module' : 'project_level_ajax',
                    'data'   : dataString,
                   'format' : 'raw'
                };                                
        $.ajax({
            type   : 'POST',
            data   : request,
            success: function (response) {
                $('.level2').html(response);
            }
        });
        return false;
     });
})(jQuery)
JS;

$doc->addScriptDeclaration($js);

require JModuleHelper::getLayoutPath('mod_project_level_ajax');
<?xml version="1.0" encoding="utf-8"?>
<extension type="module"
           version="3.0"
           method="upgrade">
    <name>Project Level Ajax</name>
    <creationDate>January 17, 2014</creationDate>
    <author>Matt Thomas</author>
    <authorUrl>http://betweenbrain.com</authorUrl>
    <copyright>Copyright (C) 2013 betweenbrain llc. All rights reserved.      </copyright>
    <license>GNU General Public License version 2, or later.</license>
    <version>3.0.1</version>
    <description>Project Level Ajax!</description>

    <files>
        <filename module="mod_project_level_ajax">mod_project_level_ajax.php</filename>
        <filename>helper.php</filename>
        <folder>tmpl</folder>
    </files>

</extension>
DROP TABLE IF EXISTS `bda_level_1`;
CREATE TABLE `bda_level_1` (
  `id` int(11) NOT NULL AUTO_INCREMENT,  
  `level1` varchar(200) COLLATE utf8_unicode_ci,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

DROP TABLE IF EXISTS `bda_level_2`;
CREATE TABLE `bda_level_2` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `level1_id` int(11),
  `level2` varchar(200) COLLATE utf8_unicode_ci,
  PRIMARY KEY (`id`),
  CONSTRAINT FOREIGN KEY (`level1_id`) REFERENCES `bda_level1`(`id`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

INSERT INTO bda_level_1 (`id`,`level1`) VALUES
(1,'Security'),
(2,'Cyber Security');

INSERT INTO bda_level_2 (`id`,`level2`,`level1_id`) VALUES
(1, 'Access Control Systems',1),
(2, 'Biometrics',1),
(3, 'CCTV & Associated Systems',1),
(4, 'Tracking Systems',1),
(5, 'Sensing Systems and Heads',1),
(6, 'Fire',1),
(7, 'Intruder Alarm Systems',1),
(8, 'Information & Data Security',1),
(9, 'Manned Security Services',1),
(10, 'Security Hardware',1),
(11, 'Weapons & Ammunition',1),
(12, 'Communications',1),
(13, 'Personnel Protection & Control',1),
(14, 'Vehicles',1),
(15, 'Audio Equipment & Systems',1),
(16, 'Ancillary Security Equipment & Services nec',1),
(17, 'Bomb Disposal',1),
(18, 'Forensics & Evidence',1),
(19, 'CBRN & Anti Terrorism',1),
(20, 'Cyber Threat Intelligence',2),
(21, 'System Recovery & Data Cleansing',2),
(22, 'Situational Awareness Products',2);