Issue with Bootstrap modal not dismissing when using click function

This is my custom function and div. When I click the function, it executes successfully but the modal window remains visible.

    <script type="text/javascript>
$(document).ready(function () {

    $("#btnRespuesta").click(function () {
        //alert('entre a btnRespuesta');
        $('#btnRespuesta').attr('disabled', true);
        $.ajax({

            url: "/PreguntasConfigs/guardarRespuesta/",
            data: { respuesta: $("#respuesta").val(), idPregunta: $("#idPreguntaAsociada").val(), idRespuesta: $("#idRespuesta").val(), tipo: $("#tipo").val(), id_periodo: $("#periodo").val() },
            success: function (result) {
                //alert(result);
                $('#preguntas' + $("#idPreguntaAsociada").val() + ' tbody').replaceWith(result);
                $("#idPreguntaAsociada").val(0);
                $("#idRespuesta").val(0);
                $("#respuesta").val("");
                $('#btnRespuesta').attr('disabled', false);
                $("#tipo option[value='-1']").prop("selected", true);
                $("#periodo option[value='-1']").prop("selected", true);


            }

        }).error(function () {
            alert('Unknown Error');
        }).fail(function () {
            alert('Error connecting to server');
        });


    });


});


</script>

<!-- Modal responses -->
<div class="modal fade" id="modalResponses" role="dialog">
    <div class="modal-dialog">
        <!-- Modal content-->
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 id="responseTitle" class="modal-title">New Response for:</h4>
                <h5 id="questionTitleResponse" class="modal-title">Question</h5>
            </div>
            <div class="modal-body">
                <div class="form-horizontal">
                    <form id="loginForm" method="post" class="form-horizontal">
                        <div class="form-group">
                            <label class="control-label col-md-3" for="question">Response</label>
                            <div class="col-md-8">
                                <input type="hidden" id="idQuestionAssociated" name="idQuestionAssociated" value="0" />
                                <input type="hidden" id="idResponse" name="idResponse" value="0" />
                                <textarea required style="resize:none;" class="form-control text-box single-line valid" class="responses" id="response" name="response" rows="3"></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-md-3" for="type">Type</label>
                            <div class="col-md-8">
                                <select id="type" class="form-control valid" required>
                                    <option value="-1">Select an option</option>
                                    <option value="I">Tax</option>
                                    <option value="D">Declaration</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-md-3" for="period">Period</label>
                            <div class="col-md-8">
                                <select id="period" class="form-control valid" required>
                                    <option value="-1">Select an option</option>
                                    <option value="01">Monthly</option>
                                    <option value="3">Bi-monthly</option>
                                    <option value="4">Quarterly</option>
                                    <option value="5">Four-Monthly</option>
                                    <option value="6">Semiannual</option>
                                    <option value="7">Annual Legal Entity</option>
                                    <option value="8">Annual Natural Person</option>
                                </select>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                            <button type="button" id="btnResponse" data-dismiss="modal" class="btn btn-primary">Save</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

Also try adding this: $ ('body') addClass("."); $ ("#modalResponses") css ("display", "none."); After the ajax function ends, but it's still not working.

Answer №1

It is recommended to dial:

$('#answersModal').modal('hide');

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The jQuery method serializeArray does not include the values of HTML textareas and checkboxes

Hello, I'm looking to send data to the server from an HTML form. The server I'm using is CodeIgniter and I'm utilizing the AJAX method. Here's the HTML form: <div id="fileupload"> <form id="upload-media-form" class="uploa ...

DotNetNuke encounters difficulties in running Jwplayer

I attempted to incorporate a jwplayer using the following code: <script src="js/jwplayer.js" type="text/javascript"></script><script type="text/javascript"> <script type="text/javascript"> $(document).ready(function() ...

What is the best way to vertically center a caption when an image is being hovered over

I'm facing an issue with aligning my caption vertically inside a div when hovering. The image within the div is larger than the div, and I want the caption to be at the center of the div. HTML <div class="container-fluid"> <div id="pag ...

how to assign a value to a field automatically in PHP

Is it possible to send values such as name, email, and contact number from one URL like to another URL at ? I would like these values to be automatically displayed on the form of the target URL (http://www.otherurl.com/test.php). I do not have access to ...

Using Jquery: Removing the strikethrough effect upon the second click!

Currently in the process of learning Jquery and experimenting with using a button to apply a "text-decoration" to a list item upon clicking. However, I encountered an issue where I couldn't figure out how to use the same button to remove the "text-dec ...

What is the best way to customize bootstrap styles?

Currently, I am attempting to modify basic CSS attributes within the default theme that is included with a new ASP.NET MVC 5 application in Visual Studio 2013. Specifically, my goal is to change the background color of the navigation menu. With the help o ...

I am unable to access the information from my api link using ajax

Before fetching data from my link (), I tested it in my browser and it worked fine. It returned JSON format, but I encountered an error when trying to access the same link with AJAX. Thank you, Below is the code snippet: <script type="text/javascript ...

The dropdown menu is being filled with 'undefined' values when using AJAX as the data source in Typeahead

I've been trying to implement typeahead functionality, but I can't seem to find a solution on Stack Overflow that works for me. I am using an ajax source to retrieve JSON data for my products, however the typeahead feature is returning all matche ...

Arrange the child elements of a div to be displayed on top of one another in an HTML document

I am struggling with a div containing code .popupClass { width: 632px; height: 210px; position: absolute; bottom:0; margin-bottom: 60px; } <div class="popupClass"> <div style="margin-left: 90px; width: 184px; hei ...

What is the correct way to align a shape with a border width in the center of its parent input button?

My newsletter subscription box features a form that spans the entire width of its parent element, causing the button to fill up all available space. To add a visual touch, I used the before CSS pseudo-element to create a small 'arrow' shape abov ...

Show the price of the item with a click of a button

There are three buttons where I can select values and input them into the button. Once all three values are selected in the buttons, I would like the product of these values to be displayed in a fourth button. Here is my HTML code: <label>S *</l ...

Create a unique bar chart plugin using Javascript/jQuery that allows users to drag and drop data

My current project involves developing a custom bar chart generator that must meet specific criteria: Input fields for entering data to display on the chart The ability to drag and resize bars once the chart is generated I've conducted research and ...

Currently, I am encountering challenges with the navigation menu on my website. The technologies I am utilizing for this project include Bootstrap 3, JQuery 2.3.1, Jade, ExpressJS

Greetings! I am diving into the world of Jade templating for Node.js and embarking on a journey to create a basic starter application using Express 4, JQuery, Bootstrap 3, and Jade. I encountered an issue while attempting to incorporate the navbar into my ...

Problem aligning ul within div element

I'm having trouble aligning my ul element in the center of a div. I tried using the margin: 0 auto method, but it's not working as expected. I've always wondered if setting the width of the ul within a div is necessary for using margin: 0 au ...

In search of a versatile multi-slide carousel solution for Angular JS

Hello everyone, we are looking to implement a carousel in our project. I came across the angular-carousel while searching online and found this helpful link http://www.bootply.com/94452. However, the carousel is written in jQuery and we will not be using ...

Execute another Ajax request using jQuery after the first Ajax callback has been completed

Looking for a solution to ensure the correct order of appended contents loaded via ajax, I have the following script: $.get('http://mydomain.com/ajax1.php/', function(data){ var data_one = $(data).find('#ajax_editor_suggestion_c ...

Encountering a 419 POST error while using Ajax in Laravel

Any help would be greatly appreciated. I've tried numerous solutions from this forum, but I just can't seem to make it work. The ajax call in question looks like this $(document).ready(function() { $("#company").click(function() { $ ...

Autofill with JavaScript - Dynamic Form Population

Looking to create a form-based HTML page. The objective is to have the second input box automatically populate based on the user's input in the first input box. I've gone through various guides and tried to implement this script, but it doesn&ap ...

Tips for eliminating a particular value using jQuery

Is there a way to remove specific data from an input text value using jQuery, but the code seems to be showing incorrect results? <input id="value1" type="hidden" name="value1" value="352880,350906,341563"> <script src="https://code.jquery.com/ ...

jquery's each method is not functioning as intended and causing unexpected issues

I'm in the midst of developing a website, and one section requires users to input their details into a form. My goal is as follows: When a user clicks the submit button with any empty fields, I want a span element (initially set to display none in CS ...