AJAX PHP function onchange select box

前端 未结 5 1860

I have a problem about which I am very confused. I have a select box with s dynamically generated using a mysqli query:

$result = mysqli_query($db, \"SELECT         


        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-16 23:34

    just change your function to a 'body'.on, and give your elements an id of 'contacts'

    $("body").on('change', '#contacts', function() {
        //get the selected value
        var selectedValue = $(this).val();
    
        //make the ajax call
        $.ajax({
            url: 'function.php',
            type: 'POST',
            data: {option : selectedValue},
            success: function() {
                console.log("Data sent!");
            }
        });
    });
    

提交回复
热议问题