如何用ajax关闭模态?

时间:2017-09-18 10:48:26

标签: javascript jquery html twitter-bootstrap

我向网络服务器发送一个ajax请求,服务器返回一个值,如果值为true,我必须关闭模态,当我关闭模态时,我无法浏览页面。 / p>

AJAX代码

$.ajax({
type: "POST",
url: "impostazioni/funzioni.php",
data: { "action": "aggiorna", "tipo": "EMail", "valore": nuova},
success:function(result){
    $("#nuova_email").val("");
    $("#conferma_email").val("");
    $("#modifica_mail").hide();
    alert("EMail aggiornata");
    $("#email").val(nuova);
    impostazioni();
}
});

HTML模式

<div id="modifica_mail" class="modal fade" role="dialog">
    <div class="modal-dialog">
        <!-- Modal content-->
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Modifica e-mail</h4>
        </div>
        <div class="modal-body">
            <table class="table" style="border:none; line:none;overflow-x:auto; border-collapse: collapse; border-spacing: 0;width: 100%;border: 1px solid #ddd;">
                <tr>
                    <td>Nuova e-mail</td>
                    <td><input type="email" placeholder="Nuova e-mail" id="nuova_email" name="nuova_e-mail"></td>
                </tr>
                <tr>
                    <td>Conferma e-mail</td>
                    <td><input type="email" placeholder="Conferma e-mail" id="conferma_email" name="conferma_e-mail"></td>
                </tr>
            </table>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default btn-sm" onclick="annulla_email()" data-dismiss="modal">Annulla</button>
            <button type="submit"  class="btn btn-default btn-sm" onclick="aggiorna_email()">Aggiorna</button>
        </div>
    </div>
</div>

你能帮我吗?

1 个答案:

答案 0 :(得分:2)

更改

$("#modifica_mail").hide();

进入正确的Bootstrap模态函数。

$("#modifica_mail").modal('hide');

这里有更多细节。 https://v4-alpha.getbootstrap.com/components/modal/#modalhide