繁体   English   中英

Ajax无法在joomla中使用我的自定义组件

[英]Ajax is not working on my customize component in joomla

我在joomla文章中遇到了问题,该文章使用Sourcerer自定义了代码。

这是我的一些有关ajax javascript的示例代码:

<script type="text/javascript">
    function showBox1(element) {
        document.getElementById('hideBox1').style.display = "";

        if (element == "")
        {
            document.getElementById("txtHint").innerHTML = "";
            return;
        }
        if (window.XMLHttpRequest)
        {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        }
        else
        {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function()
        {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
            {
                document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET", "home/matedis/public_html/joomla/Add_Edit_Intake/getuser.php?q=" + element, true);
        xmlhttp.send();

    }

</script>

将值传递给函数的代码在这里:

<?php
// Get default database object
$db = JFactory::getDBO();

// Get a new JDatabaseQuery object
$query = $db->getQuery(true);

// Build the query
$query->select($db->quoteName('campusid'));
$query->from($db->quoteName('campus'));
$query->where($db->quoteName('collegeid') . '=' . $db->quote('1'));

// Set the query for the DB oject to execute
$db->setQuery($query);
// Get the DB object to load the results as a list of objects
$results = $db->loadObjectList();
if ($results) {
    foreach ($results as $result) {
        echo "<label class='option block spacer-t10'>";
        echo "<input type='radio' id ='campusID' name='campusID' value='$result->campusid' onChange='showBox1(this.value)'><span class='radio'></span>";
        echo $result->campusid;
        echo '</label>';
    }
} else {
    echo 'Error';
}
?>

这是我的getuser.php代码:

   <?php

$q = intval($_GET['q']);
define( 'JPATH_BASE', $_SERVER[ 'DOCUMENT_ROOT' ] ); // define JPATH_BASE on the external file
require_once( JPATH_BASE . DS . 'libraries' . DS . 'import.php' ); // framework
require_once( JPATH_BASE . DS . 'configuration.php' ); // config file
$db = JFactory::getDBO();


$sql="SELECT courseid FROM course WHERE campusid = '".$q."'";




// Build the query
$query->select($db->quoteName('courseid'));
$query->from($db->quoteName('course'));
$query->where($db->quoteName('campusid').'='. $db->quote($q)); //This later must change to retrieve id from current user

// Set the query for the DB oject to execute
$db->setQuery($query);// Get the DB object to load the results as a list of objects
$results = $db->loadObjectList();
if($results){
     foreach($results as $result)
     {
        echo $result->courseid;
 } 

}
else{ echo 'Error';}
?>

我犯了什么错误吗? 因为它没有显示输出,所以我希望从这里http://www.w3schools.com/php/php_ajax_database.asp参考代码。 抱歉造成任何不便,因为我还是joomla和php ajax的新手。

xmlhttp.open("GET","home/matedis/public_html/joomla/Add_Edit_Intake/getuser.php?q="+element,true);

这是public_html的真实路径吗? 没有..

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM