zencart中的ajax问题

时间:2012-05-10 05:11:52

标签: php ajax zen-cart

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

<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>";
}

?>

2 个答案:

答案 0 :(得分:0)

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

如果不知道你在/includes/modules/pages/subcategory/header_php.php文件中做了什么,或者你甚至创建了一个,那么你的问题就无法准确回答。有可能你输入tpl_subcategory_default.php的代码可能会进入上面提到的header_php.php文件,最后是一个die()语句,并完成你似乎正在寻找的相同的东西。

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

答案 1 :(得分:0)

要删除页眉,页脚等,您可以覆盖tpl_main_page.php。转到此目录/ includes / templates / custom模板。根据您的信息,您创建了main_page = getsubcategory页面。所以在这个目录下创建一个名为getsubcategory的文件夹。然后从includes / templates / custom template / common /复制tpl_main_page.php并将其粘贴到/ includes / templates /您的自定义模板/ 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;

}