Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-03-03
4
Medium Priority
?
631 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 1200 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

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…
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)
Suggested Courses

688 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