发送新值后自动刷新下拉列表

时间:2016-02-22 11:00:32

标签: php jquery mysql ajax

我有一个下拉代码:

和其他块:

<script type="text/javascript">
    /*Primo pulsante attributo*/

    $(document).ready(function() {
        $('#bloccoetapulsante').click(function() {

            var dati = $("#campo").val();

            $.ajax({
                url: "database/bloccoattributi.php",
                data: 'dati=' + dati,
                method: "POST",
                dataType: "HTML",
                cache: false,
                success: function(data) {
                    alert("Attributo inserito");

                }
            });
        });
    });
</script>

<div class="row">
    <div class="col-lg-3">
        <div class="input-group">
            <input name="campo" id="campo" type="text" class="form-control" placeholder="Inserisci altro">
            <span class="input-group-btn">
        <button class="btn btn-default" type="button" id="bloccoetapulsante"><span class="glyphicon glyphicon-plus"></span></button>
            </span>
        </div>
        <!-- /input-group -->

如何在使用按钮(bloccoetapulsante)添加新值后更新下拉列表而不重新加载页面?

由于

2 个答案:

答案 0 :(得分:2)

success: function (data) {
    $("#id").html("Attributo inserito"); // #id as a dropdown Id
}

$("#id").append("Attributo inserito");

答案 1 :(得分:1)

在ajax调用后添加dispatch_async(dispatch_get_main_queue(), { //call here getCommentFromMYSQL() if(resultValue == "Success"){ } else{ let error = UIAlertController(title: "Error", message: "Please check your network configuration!:-(", preferredStyle: .Alert) let cancel = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil) let ok = UIAlertAction(title: "OK", style: .Default, handler: nil) error.addAction(cancel) error.addAction(ok) } }) 。它会刷新$('.selectpicker').selectpicker('refresh');