0
votes

I'm sending <form> data through ajax in bootstrap modal. How do I make the modal window open until a value has returned and then display a notification <div>?

The notification div will display form validation, and to manually close the modal the user needs to click the close button, or outside the modal window.

Below is my code, simplified version:

$.post(url, {
    data:data }
    ,function(html){
        if(html==1){
            //show <div class="A">  here
        }
        else{
           //show <div class="B">  here
        }
});
1
Show me your <form> ?? - Sanu Uthaiah Bollera
Is the modal closing on its own? It shouldn't be. If you're just trying to show the modal, it's $("#myModal").modal("show");. To show the div you could use $(".A" ).show();. - Matthew Johnson

1 Answers

1
votes

Use $.ajax

$.ajax({
    type: 'POST',
    url: url,
    data: data,
    beforeSend: function() {
        // Write code for showing the modal here
       // You can also set a loading image here
    },
    success: function(html) {
        // code for success notification
    },
    error: function(xhr) { // if error occured
        // code for showing error
    }
});