Php zencart中的ajax问题

Php zencart中的ajax问题,php,ajax,zen-cart,Php,Ajax,Zen Cart,我有一些主类别和每个主类别的子类别。我有一个包含主类别的下拉列表,当我选择主类别时,子类别下拉列表显示该主类别的子类别。。 我使用下面的代码,但这表明子类别框包含整个页面的页眉和页脚 <select name="main_category" id="main_category" onchange="showSubCategory(this.value)"> <option>--Select--</option> </select>

我有一些主类别和每个主类别的子类别。我有一个包含主类别的下拉列表,当我选择主类别时,子类别下拉列表显示该主类别的子类别。。 我使用下面的代码,但这表明子类别框包含整个页面的页眉和页脚

<select name="main_category" id="main_category" onchange="showSubCategory(this.value)">
        <option>--Select--</option>
</select>


<script type="text/javascript">
        function showSubCategory(str)
        {

            if (str.length==0)
            {
                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)
                {
                    alert(xmlhttp.responseText);
                    document.getElementById("subcategory").innerHTML=xmlhttp.responseText;
                }
            }
            xmlhttp.open("GET","index.php?main_page=getsubcategory&cid="+str,true);
            xmlhttp.send();
        }
    </script>
在tpl_子类别中_default.php包含

<?php
$cid=$_GET['cid'];
$sql="select cd.categories_name, cd.categories_id
                             from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
                             where c.parent_id = '" . (int) $_GET['cid'] . "'
                             and c.categories_id = cd.categories_id
                             and c.categories_status= 1";

$r=mysql_query($sql);

while($row=mysql_fetch_array($r))

{
echo "<option value=$row[categories_id]>$row[categories_name]</option>";
}

?>

它用页眉和页脚显示整个页面,因为您是通过index.php?main_page=foo访问页面的,但没有添加架构来用您自己的页面特定输出替换正常的模板系统输出。。。ie:直接跳转到输出,而不首先调用每个页面上显示的正常内容

如果不知道您在/includes/modules/pages/subcategory/header_php.php文件中做了什么,或者您是否创建了一个文件,您的问题就无法真正得到准确的回答。您放入tpl_subcategory_default.php的代码很可能会进入上面提到的头文件_php.php,最后是一个die语句,并完成您似乎正在寻找的相同任务


如果您提供了有关您迄今为止所做工作的更多信息,那么完全回答您的问题会更容易。

要删除页眉、页脚等,您可以覆盖tpl_main_page.php。转到此目录/includes/templates/custom template。根据您的信息,您已经创建了main_page=getsubcategory页面。因此,在此目录下创建一个名为getsubcategory的文件夹。然后从includes/templates/custom template/common/复制tpl_main_page.php,并将其粘贴到/includes/templates/your custom template/getsubcategory中。然后在tpl_main_page.php文件中执行以下更改

if (in_array($current_page_base,explode(",",'getsubcategory')) ) {

    $flag_disable_left = true;
    $flag_disable_header = true;
    $flag_disable_footer = true;

}