Javascript Ajax无法在joomla中使用我的自定义组件
我的joomla文章有问题,我用Sourcerer自定义了代码 下面是我的一些ajax javascript示例代码:Javascript Ajax无法在joomla中使用我的自定义组件,javascript,php,ajax,joomla,Javascript,Php,Ajax,Joomla,我的joomla文章有问题,我用Sourcerer自定义了代码 下面是我的一些ajax javascript示例代码: <script type="text/javascript"> function showBox1(element) { document.getElementById('hideBox1').style.display = ""; if (element == "") { docum
<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>
功能显示框1(元件){
document.getElementById('hideBox1').style.display=“”;
如果(元素==“”)
{
document.getElementById(“txtHint”).innerHTML=“”;
返回;
}
if(window.XMLHttpRequest)
{//IE7+、Firefox、Chrome、Opera、Safari的代码
xmlhttp=新的XMLHttpRequest();
}
其他的
{//IE6、IE5的代码
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数()
{
if(xmlhttp.readyState==4&&xmlhttp.status==200)
{
document.getElementById(“txtHint”).innerHTML=xmlhttp.responseText;
}
}
open(“GET”、“home/matedis/public_html/joomla/Add_Edit_aintain/getuser.php?q=“+element,true”);
xmlhttp.send();
}
将值传递给函数的代码如下:
<?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';}
?>
这是公共html的真实路径?否…这是我的php文件在我的服务器中的路径。这是我的ajax问题的原因吗?您的服务器主机配置为相对路径“home/matedis/public\u html/joomla/Add\u Edit\u intraction/”?我不这么认为,因为它失败了,那么我的getuser.php文件应该放在哪个文件夹中?我目前正在使用cpanel来配置文件管理器,Add_Edit_taken是我刚刚在joomla文件夹中创建的文件夹。但是joomla主机的顶端可能位于public_html/目录中,您需要设置ajax请求路径,如:/joomla/Add_Edit_taken/getuser.php?q=或/Add_Edit_taken/getuser.php?q=抱歉英语不好:)
xmlhttp.open("GET","home/matedis/public_html/joomla/Add_Edit_Intake/getuser.php?q="+element,true);