Zencart中的Ajax问题


ajax issue in zencart

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

<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_subcategory_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:直接跳转到输出,而无需首先调用出现在每个页面上的正常内容。

如果不知道您在/include/modules/pages/subcategory/header_php.php 文件中做了什么,或者您是否已经创建了一个,您的问题就无法真正准确回答。您放入tpl_subcategory_default.php的代码可能会进入上面提到的header_php.php文件,然后在末尾添加 die() 语句,并完成您似乎正在寻找的相同事情。

如果您提供有关到目前为止所做工作的更多信息,则更容易完全回答您的问题。

要删除页眉,页脚等,您可以覆盖tpl_main_page.php。转到此目录/include/templates/custom template。根据您的信息,您创建了main_page=get子类别页面。因此,在此目录下创建一个名为 getsubcategory 的文件夹。然后从包含/模板/自定义模板/通用/复制tpl_main_page.php并将其粘贴到/include/templates/您的自定义模板/get子类别中。然后在tpl_main_page.php文件中执行以下更改。

if (in_array($current_page_base,explode(",",'getsubcategory')) ) {
    $flag_disable_left = true;
    $flag_disable_header = true;
    $flag_disable_footer = true;
}