-1

I want to get a cascading dropdown in pyrocms. I wrote the following ajax code. But it always displays dialog alert(error). That is ajax request is failing.

<script type="text/javascript">
        $(document).ready(function() {
            $('#vehicle_cat_id').change(function() { //any select change on the dropdown with id country trigger this code
                //$("#cities > option").remove(); //first of all clear select items
                var cat_id = $('select#vehicle_cat_id').val(); // here we are taking country id of the selected one.
                //alert(cat_id);
                $.ajax({
                    type: "POST",
                    url: "<?= base_url('admin/vehicle/modellists') ?>", //here we are calling our user controller and get_cities method with the country_id
                    data: 'cat_id = '+cat_id,
                    success: function(html)
                    {
                        //alert('test');
                        $('select#vehicle_model_id').html(html);
                    },
                    error: function(){
                        alert('failed');
                    }
                });

            });
        });
    </script>

What have i done wrong?

nzy
  • 854
  • 2
  • 15
  • 28
  • "What have i done wrong?" — You haven't told us what the JavaScript error console says. You haven't told us if you got the expected data back from the request (by examining the Net tab of your browser's developer tools). You have completely ignored the arguments sent to the error function (which tell you what error jQuery is reporting). – Quentin Dec 22 '14 at 10:50

1 Answers1

0

I have made a correction, hope that helps :

<script type="text/javascript">
        $(document).ready(function() {
            $('#vehicle_cat_id').change(function() { //any select change on the dropdown with id country trigger this code
                //$("#cities > option").remove(); //first of all clear select items
                var cat_id = $('select#vehicle_cat_id').val(); // here we are taking country id of the selected one.
                //alert(cat_id);
                $.ajax({
                    type: "POST",
                    url: "<?= base_url('admin/vehicle/modellists') ?>", //here we are calling our user controller and get_cities method with the country_id
                    data: {
                     'cat_id' : cat_id
}
                    success: function(html)
                    {
                        //alert('test');
                        $('select#vehicle_model_id').html(html);
                    },
                    error: function(){
                        alert('failed');
                    }
                });

            });
        });
    </script>
Halayem Anis
  • 7,654
  • 2
  • 25
  • 45