web-dev-qa-db-fra.com

Comment ouvrir bootstrap modal sans bouton-cliquer?

J'ai besoin de faire apparaître un bootstrap modal dans la fonction de succès d'ajax dans ma page. La fonction de succès est appelée lorsque le formulaire est soumis .., il existe donc une méthode pour faire apparaître le bootstrap modal sans clic de bouton. Je suis une recrue .., s'il vous plaît aidez-moi ici .. Ceci est mon appel ajax ..

     $("#form").submit(function(e)
   {
       $.ajaxSetup({
           headers:{'X-CSRF-Token' : $('meta[name=_token]').attr('content')}
       });
    e.preventDefault(); //STOP default action
    var postData = $(this).serializeArray();
    console.log(postData);


    var formURL =  "http://localhost:8000/v1/people_roles";

    $.ajax(
    {


        url :formURL ,
        type: "POST",
        data : postData,
        success:function(response, textStatus, jqXHR)
    {

        if(response.parent==1)
        {
            $("#getCode").html(response);
            $("#getCodeModal").modal('show');
             window.location.href="/web/staff/detail.php?id="+response.people_id;
        }
        else
        {
            //console.log(response);
            window.location.href="/web/staff/detail.php?id="+response.people_id;
        }
    }



    });   
    });

et voici mon code modal html ..

    <div class="modal fade" id="getCodeModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-lg">
     <div class="modal-content">
     <div class="modal-header">
         <h4 class="modal-title">Modal title</h4>
     </div>
     <div class="modal-body">
         <p><strong>Lorem Ipsum is simply dummy</strong> text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown
             printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting,
             remaining essentially unchanged.</p>
     </div>
     <div class="modal-footer">
         <button type="button" class="btn btn-white" ng-click="cancel()">Close</button>
         <button type="button" class="btn btn-primary" ng-click="ok()">Save changes</button>
     </div>
   </div>
  </div>
</div>     
10
alex_gabriel

$("#getCodeModal").modal('show');

vous pouvez vous y référer pour plus d'informations: Comment ouvrir une fenêtre modale Bootstrap utilisant jQuery?

21
JK ABC