How to display modal form after submitting through AJAX
<p>I Have a login in form inside a modal. After submitting the form i am getting success or failure message..let's say failure message. But when i am reopening the modal same message is appearing instead of log in form. After refreshing the page only modal is showing the log in form.</p>

<p>Here is my code....please help me how can i fix it so it will show the log in form when i reopen the modal after submission.</p>

<pre><code>    &lt;!--  Sign in feature starts here --&gt; 
&lt;div id="sign_in" class="modal fade" role="dialog"&gt;
  &lt;div class="modal-dialog"&gt;
    &lt;div class="modal-content"&gt;
      &lt;div class="modal-header"&gt;
        &lt;button type="button" class="close" data-dismiss="modal"&gt;&amp;times;&lt;/button&gt;
        &lt;h4 class="modal-title"&gt;Sign In&lt;/h4&gt;
      &lt;/div&gt;
      &lt;div class="modal-body"&gt;
&lt;div class="panel-body" id="form"&gt;
 &lt;form class="form-horizontal" role="form" method="post" id="log-in" &gt;
  &lt;fieldset&gt;
                                &lt;div class="form-group"&gt;
                               &lt;input class="form-control" id="username" placeholder=" Username or Mobile No." type="text" autofocus  AutoComplete=off required&gt;
                                &lt;/div&gt;
                                &lt;div class="form-group"&gt;
                               &lt;input class="form-control" id="password" placeholder=" Enter Password" type="password" autofocus  AutoComplete=off required&gt;
                                &lt;/div&gt;
                                 &lt;!-- Change this to a button or input when using this as a form --&gt;
                                &lt;button class="btn btn-lg btn-success btn-block" type="submit"&gt;Sign In&lt;/button&gt;
                            &lt;/fieldset&gt;
  &lt;/form&gt; &lt;/div&gt;
&lt;/div&gt;
          &lt;/div&gt; 
&lt;/div&gt;&lt;/div&gt;
 &lt;!--  Sign In feature ends here --&gt;
&lt;script type="text/javascript"&gt;
$(document).ready(function()
{   
    $(document).on('submit', '#log-in', function()
    {
        var data = $(this).serialize();
        $.ajax({
        type : 'POST',
        url  : '&lt;?php echo site_url('verifylogin');?&gt;',
        data : data,
        success :  function(data)
                   {                        
                        $("#log-in").fadeOut(500).hide(function()
                        {
                            $("#form").fadeIn(500).show(function()
                            {
                                $("#form").html(data);
                                if(data != null &amp;&amp; data == "success"){ //redirect...
                        window.location.replace('home.php');
                }
                            });
                        });

                   }
        });

        return false;
    });
});
&lt;/script&gt;
</code></pre>