Show ajax result

1

Good morning, I have the following doubt. I'm taking the first steps with javascript and I'm doing a query using ajax and I have the following problem with the code.

$(document).ready(function(){
    $(document).on('change','#organica',function(){
        var org = $(this).val();
        var div=$(this).parent();
        var op=" ";

        $.ajax({
            type:'get',
            dataType: 'json',
            url:'{!! URL::to('findPrograma')!!}',
            data: {'organica':org},
            success:function(data){

                //  no funciona
            op+='<option value="0" selected disabled>chose product</option>';
                for(var i=0;i<data.length;i++){
                op+='<option value="'+data[i].programa+'">'+data[i].programa+'</option>';
                    };

            div.find('#programa').append(op);

                                //  funciona
            $('#programa').append('<option>--Seleccionar--</option>');
            for(var i=0;i<data.length;i++){
            $('#programa').append('<option value="'+data[i].programa+'">'+data[i].programa+'</option>');
            }
        }
        });
    });
    
asked by Peta P3t4d0r Zeta 02.02.2018 в 00:04
source

1 answer

1

Yes in your HTML , you have a ID it would not be necessary to search for this element with find () since the ID must be unique , then it would only be necessary to directly access this element.

div.find('#programa').append(op); //No

$('#programa').append(op); //Sí
    
answered by 02.02.2018 / 00:22
source