Solved

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

Posted on 2014-03-03
4
628 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 53

Accepted Solution

by:
Scott Fell,  EE MVE earned 300 total points
ID: 39902412
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
ID: 39903841
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 53

Expert Comment

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

Author Closing Comment

by:brihol44
ID: 39915459
I re-worked this but thx!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

DOM Attributes and Properties treatment with jQuery 1.6 by Ivo Stoykov jQuery (http://jquery.com/) 1.6 introduces .prop() (http://api.jquery.com/prop/) and .removeProp() (http://api.jquery.com/removeProp/) methods which allow modifying or removi…
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

710 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