Twitter Bootstrap Modal Form Submit

后端 未结 5 661
鱼传尺愫
鱼传尺愫 2020-12-05 03:29

I\'ve recently been fiddling around with twitter bootstrap, using java/jboss, and i\'ve been attempting to submit a form from a Modal interface, the form contains just a hid

5条回答
  •  一向
    一向 (楼主)
    2020-12-05 03:49

    Old, but maybe useful for readers to have a full example of how use modal.

    I do like following ( working example jsfiddle ) :

    $('button.btn.btn-success').click(function(event)
    {
    
    event.preventDefault();
    
    $.post('getpostcodescript.php', $('form').serialize(), function(data, status, xhr)
        {
            // do something here with response;
            console.info(data);
            console.info(status);
            console.info(xhr);
        })
        .done(function() {
            // do something here if done ;
            alert( "saved" );
        })
        .fail(function() {
            // do something here if there is an error ;
            alert( "error" );
        })
        .always(function() {
            // maybe the good state to close the modal
            alert( "finished" );
            // Set a timeout to hide the element again
            setTimeout(function(){
              $("#myModal").hide();
            }, 3000);
        });
    });
    

    To deal easier with modals, I recommend using eModal, which permit to go faster on base use of bootstrap 3 modals.

提交回复
热议问题