【问题标题】:ajax issue in zencartzencart中的ajax问题
【发布时间】:2012-05-18 15:53:27
【问题描述】:

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

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

?>

【问题讨论】:

    标签: php ajax zen-cart


    【解决方案1】:

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

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

    如果您提供有关您目前所做工作的更多信息,将更容易完整地回答您的问题。

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 2016-11-28
        • 2011-10-09
        • 2019-08-02
        • 2013-09-02
        • 2012-10-17
        • 2012-03-21
        • 2011-05-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多