Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 632
  • Last Modified:

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

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
brihol44
Asked:
brihol44
  • 2
  • 2
1 Solution
 
Scott Fell, EE MVEDeveloperCommented:
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
 
brihol44Author Commented:
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
 
Scott Fell, EE MVEDeveloperCommented:
I understand. I was just trying to make an easy test.
0
 
brihol44Author Commented:
I re-worked this but thx!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now