【问题标题】:Joomla AJAX call losing Joomla database classJoomla AJAX 调用丢失 Joomla 数据库类
【发布时间】:2012-10-19 17:09:46
【问题描述】:

我目前正在将一些功能构建到 Joomla 构建中,而结果是在选择框更改时从数据库返回的。 我遇到的问题是当我进行Ajax 调用时,我得到一个Class JFactory not found' 错误,我认为这是因为运行php 代码的文件在AJAX 时不被认为在Joomla 框架内打电话了吗? 我试图自己解决这个问题,但遇到了麻烦。 谁能指出我在哪里出错的正确方向?

Ajax 调用(在 index.php 中):

<script type="text/javascript">
    var url = "<?php echo $this->baseurl; ?>/templates/<?php echo $this->template; ?>/directory_code.php";
    jQuery(document).ready(function() {
        jQuery('#city').change(function() {         
        jQuery.ajax({
            url: url,
            type: "POST",
            data: jQuery("#city").serialize(),
            dataType: 'json',
            success: function(data) {
            alert('data');
            }
        });
    });
});
</script>

以及函数(在一个名为 directory_code.php 的文件中):

if(isset($_POST)) {
    if(isset($_POST['city'])) {
        $city = $_POST['city'];
        $suburbs = populateSuburbs($city);
    }
}   

function populateSuburbs($city) {               
    $db = JFactory::getDBO();
    $query = "SELECT DISTINCT suburb FROM vyj20_contact_details";
    $db->setQuery($query);
    $results = $db->loadObjectList();
    foreach($results as $key => $result) {
        $data['suburb'][] = array(
            $key => $result->suburb
        );
    }
}

非常感谢

【问题讨论】:

标签: php ajax database joomla


【解决方案1】:

代码defined( '_JEXEC' ) or die( 'Restricted access' ); 通常限制ajax

函数,因此您需要使用define('_JEXEC', 1);

注意你需要使用define而不是defined,所以如果你还没有这样做,我建议你尝试一下。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-28
    • 1970-01-01
    • 2012-03-24
    • 1970-01-01
    • 2011-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多