Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Ajax更改(函数()未触发_Javascript_Php_Ajax - Fatal编程技术网

Javascript Ajax更改(函数()未触发

Javascript Ajax更改(函数()未触发,javascript,php,ajax,Javascript,Php,Ajax,我正在尝试为产品创建3个下拉菜单,类别-子类别-子类别 例如:类别健康、美容和个人==子类别化妆=>子类别-眼线。主要类别适当填充,子类别应根据用户选择填充,如果选择健康、美容个人护理,则应该填充子类别。我编写了Ajax更改函数以动态地获取值。从用户处重新加载页面。但是,它正在从用户处接收值,但未填充子类别。在下面的代码段中,如果更改了cat_id,则将触发此函数。但是,即使用户在主类别中选择了一个选项,cat_id也不会接收任何值。请帮助我或建议我需要对r执行什么操作解决这个 $(docume

我正在尝试为产品创建3个下拉菜单,类别-子类别-子类别 例如:类别健康、美容和个人==子类别化妆=>子类别-眼线。主要类别适当填充,子类别应根据用户选择填充,如果选择健康、美容个人护理,则应该填充子类别。我编写了Ajax更改函数以动态地获取值。从用户处重新加载页面。但是,它正在从用户处接收值,但未填充子类别。在下面的代码段中,如果更改了cat_id,则将触发此函数。但是,即使用户在主类别中选择了一个选项,cat_id也不会接收任何值。请帮助我或建议我需要对r执行什么操作解决这个

$(document).ready(function(){

 $('#cat_id').change(function() 
 {

        var categoryId = $(this).val();
       // alert(categoryId);


   $.post("<?php echo DEFAULT_URL ?>/addProduct/ajax_getSubCategory", {categoryId: categoryId}, function(data) 

   {

       if (data) {

          // $('#cat_id').html(data);

           $('#subcat_id').html(data);

           $('#subsubcat_id').html('<option>Select Sub Sub Category</option>');

                 }

    });

});

});

这可能是问题的根源:

更改:

var categoryId = $(this).val();
致:


目前,您正在尝试获取下拉列表的值,而不是其选定值。

这是我用于下拉表单的html代码。。。 /addProduct'enctype='multipart/form data'>

                                                <fieldset>

                                                    <legend>Category Information</legend>

                                                    <div class="required">

                                                        <label for="category">Main Category

                                                            <font color="red" title="This field is required for registration.">*</font></label>

                                                        <?php if(isset($merchantData->membership_package) && $merchantData->membership_package==2)

                                                            $categoryId=1;

                                                        if(isset($categoryId) && $categoryId!='')

                                          $whereCondition="category_id='".$categoryId."' && is_active='1' && parent_id='0' order by category_name";

                                                        else

                                                            $whereCondition="is_active='1' && parent_id='0' order by category_name";

                                                        ?>

                                                        <?php

                                                        echo $obj_category->selectBox('cat_id', 'Select Category', 'category_id', 'category_name', isset($cat_id) ? $cat_id :"",$whereCondition, 'class="validate[required]"');


                                                        ?>   



                                                    <div class="clear"></div>

                                                    <small>Please select the best combination of category and sub-categories for your product</small>

                                                    </div>

                                                    <div class="required">

                                          <label for="sub_category">Sub Category<font color="red" title="This field is required for registration.">*</font></label>

                                                        <?php


                                                        if (isset($cat_id) && !empty($cat_id)) {



                                                     echo $obj_category->selectBox('subcat_id', 'Select Sub Category', 'category_id', 'category_name', 
isset$SUBACT_id?$SUBACT_id:,是否处于活动状态='1'且父项_id='。$cat_id。'order by category_name',class=validate[required]

                                                        } else {

                                                            ?>

                                                            <select name="subcat_id" id="subcat_id" title="Sub Category" class="validate[required]">

                                                                <option>Select Sub Category</option>

                                                            </select>

                                                        <?php } ?> 

                                                        <div class="required">

                                                            <label for="sub_sub_category">Sub Sub Category<font color="red" title="This field is required for registration.">*</font></label>

                                                            <?php


                                                            if (isset($subcat_id) && !empty($subcat_id)) {

                                                                echo $obj_category->selectBox('subsubcat_id', 'Select Sub Sub Category', 'category_id', 'category_name', isset($subsubcat_id) ? $subsubcat_id : '', "is_active = '1' and parent_id ='" . $subcat_id . "' order by category_name", 'class="validate[required]"');

                                                            } else {

                                                                ?>

                                                                <select name="subsubcat_id" id="subsubcat_id" title="Sub Sub Category" class="validate[required]">

                                                                    <option>Select Sub Sub Category</option>

                                                                </select>

                                                            <?php } ?> 

                                                        </div>

                                                </fieldset>

谢谢你的回复。我试过了,但它不起作用。cat_id没有改变。它仍然接收空值。如果cat_id改变了,那么只有更改功能会被触发。我不知道怎么做……你能发布你的html吗?更改功能不是你唯一想被触发的吗?我想在cat_id已更改。但是,当我选择主类别值时,cat_id未收到任何值。请发布由selectBox方法生成的HTML,好吗?您应该删除此项,并用更新的代码编辑原始问题
                                                        } else {

                                                            ?>

                                                            <select name="subcat_id" id="subcat_id" title="Sub Category" class="validate[required]">

                                                                <option>Select Sub Category</option>

                                                            </select>

                                                        <?php } ?> 

                                                        <div class="required">

                                                            <label for="sub_sub_category">Sub Sub Category<font color="red" title="This field is required for registration.">*</font></label>

                                                            <?php


                                                            if (isset($subcat_id) && !empty($subcat_id)) {

                                                                echo $obj_category->selectBox('subsubcat_id', 'Select Sub Sub Category', 'category_id', 'category_name', isset($subsubcat_id) ? $subsubcat_id : '', "is_active = '1' and parent_id ='" . $subcat_id . "' order by category_name", 'class="validate[required]"');

                                                            } else {

                                                                ?>

                                                                <select name="subsubcat_id" id="subsubcat_id" title="Sub Sub Category" class="validate[required]">

                                                                    <option>Select Sub Sub Category</option>

                                                                </select>

                                                            <?php } ?> 

                                                        </div>

                                                </fieldset>