How to make a query using AJAX from a ComboBox

0

I have a ComboBox that loads the option from the database.

I need that when selecting any data, load the query, depending on the selected option, all this with AJAX.

    
asked by Alejandro Melendez 17.10.2016 в 06:53
source

3 answers

2

I recommend using onchange .

<select onchange="myFunction()">

Then capture the value of the select (ComboBox) and use the AJAX in the function assigned to onchange .

    
answered by 17.10.2016 в 19:12
1

Add an ajax function in the onclick event. You pass, for example, the id of the element that you have selected to be able to make the query in the database.

elemento.addEventListener('click',function(event){
    llamarAjax(event.id);
});
    
answered by 17.10.2016 в 11:12
0

You could join the change event of the combo and there make the ajax call

<script>
    $(function(){

        $("#comboId").change(function(){

            var seleccion = $(this).val();

            $.ajax({
                type: "POST",
                url: "url",
                data: seleccion,
                datatype: "application/json",
                success: function (data) {
                    $('#result').html(data);
                }
            });

        });

    });
</script>

In this case I use jquery to control the event and also invoke the server through ajax

    
answered by 17.10.2016 в 19:09