1

2 つの依存ドロップダウンを設定するために、jQuery.ajax を使用していますが、いくつか問題があり、$.ajax に設定したコントローラー アクションの URL にアクセスできないと思います。

これは私のコントローラーアクションコードです:

 public function fillIncidentsAction()
      {
            $request = $this->getRequest();
            if ($request->isPost())
            {
                $code_categ = (int) $request->getPost('code_categ',0);           
                $data = new JsonModel(array(
                    'success' => true,
                    'results' => $this->getTableInstance('TypeIncidentTable')
                                        ->getListTypeIncident($code_categ),
                ));
                return $data;

            }
        }

これは私のjs関数の主要部分です

$('#'+source).change(function() {

    if($('#'+source).val() != '')
     {

        $.ajax({
            type:  'POST',
            async: false,
            url:   url,
            cache: true,
            dataType: 'json',
            data:  { code_categ: $('#'+source).val() },
            success: function(data){
            alert(data.success);//<------ i added this to test if this function is executed or not

                if(data.success)
                {
                    $('#'+target).prop('disabled', true);
                    if(data.results != ""){
                        var options = new Array();
                        $.each(data.results, function(key, value){
                           options[((key) ? key : 0)] = '<option value="' + key + '">' + value + '</option>';
                        });
                        $("#"+target).html(options.join(''));

                        $('#'+target).prop('disabled', false);;
                    }
                }
            },


        });

どこが間違っているのかわかりません。助言がありますか?手伝ってくれてありがとう !

申し訳ありませんが、これは私のURLを設定する方法です:

<script type="text/javascript">
 $(document).ready(function() {
  var url = "<?php echo $var =$this->url('gims/default', array('controller' =>       'evenement', 'action' => 'fill_incidents')); ?>";

// initialize the js function
dependentDropDown('firstList','secondList',url);
});
</script>

これがあなたに詳細を与えることを願っています。

4

1 に答える 1