Solved

Trying to close boostrap modal on $.ajax post form.

Posted on 2014-03-03
4
615 Views
Last Modified: 2014-03-08
Hello, I seem to be having a issue with a modal window not fully closing. My order of operation is...

1. Trigger the modal window
2. Do my thing ordering the elements within the modal window
3. Behind the modal my elements re-order themselves.
4. When done and I close the window I'm left with the default smokey bg and the modal window does dissapear but it seems that only half the modal stuff goes away.
5. Everything else works perfectly.

Just the main snippets of code are below...

function persist() {

  var data = $("#sortable").sortable('toArray');
  var datax = "order=" + data;

  $.ajax({
     url: "app/inc/inc_order_categories.cfm",
     dataType: "json",
     data: datax,
     success: function () {

     	$("#myModal2").modal('hide');
     	getData();
     },
     error: function (xhr, ajaxOptions, thrownError) {
     alert(xhr.status);
     alert(thrownError);
     }
  });

}

function getData() {

	$("#getUserData").load("app/inc/inc_get_user_data.cfm").fadeIn("fast");

};

Open in new window


<div id="getUserData"></div>

Open in new window

0
Comment
Question by:brihol44
  • 2
  • 2
4 Comments
 
LVL 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 300 total points
Comment Utility
There must be something else going on.  I have a test here http://jsbin.com/hakay/1/ that when you click the blue button the modal will open and close programatically.
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery.min.js"></script>
<link href="http://getbootstrap.com/dist/css/bootstrap.css" rel="stylesheet" type="text/css" />
<script src="http://getbootstrap.com/dist/js/bootstrap.js"></script>
<script>
  $(function() {
 
    $('.btn-lg').click(function(){
   $('#myModal').modal('show')
  
  });
$('#myModal').on('shown.bs.modal', function (e) {
 $('.btn').hide();
  $('#myModal').modal('hide');
})
  });
  </script>
    
  <meta charset="utf-8">
  <title>JS Bin</title>
  <script>
    
    </script>
</head>
<body>
<!-- Button trigger modal -->
<button class="btn btn-primary btn-lg">
  Launch demo modal
</button>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
      stuff
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

</body>
</html>

Open in new window


Can you post your modal code (except the body)

I don't think this has anything to do with it, but be consistent.  Either use double quotes or single quotes. I found when I have done  the same thing my js breaks.
$("#myModal2").modal('hide');

Open in new window

0
 

Author Comment

by:brihol44
Comment Utility
Thx for the help. Your code is a little different in that I'm making my ajax request. And upon a successful update in the $.ajax part the <div id="getUserData"></div> content refreshes asynchronously from the getData() call .

When I removed that getData() part within the success parameter everything works fine but my content within <div id="getUserData"></div> doesn't reflect the change or get refreshed. Buy maybe it's the " vs ' single tag quotes. I'll try that this evening but I think I did try that as well. thx!
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
Comment Utility
I understand. I was just trying to make an easy test.
0
 

Author Closing Comment

by:brihol44
Comment Utility
I re-worked this but thx!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now