Remove the javascript file once the modal dialog has been closed

One of the challenges I'm facing is with a modal dialog that has been customized to appear on the right side of the customer's browser. Depending on the icon clicked in the navigation bar, an ajax call is made and an HTML fragment is loaded into the modal-body.

<a class="nav-link right-menu" role="button" data-bs-toggle="modal" data-bs-target="#rightSubMenu" data-id="admin-menu">
    <i class="fas fa-users-crown"></i>
</a>

The issue arises when loading a dashboard for admins which refreshes DIVs every 5 minutes using setInterval. Even after closing the modal dialog, setInterval continues to run.

I tried clearing the modal-body contents upon modal close, but it seems that doesn't completely unload the JS files loaded as part of the fragment.

How can I ensure that all JS files are unloaded when the modal is closed, especially since I'll be reusing the modal dialog for other HTML fragments with their own JS files?

I appreciate any insights or suggestions you may have. Thank you!

Answer №1

It might be a good idea to try using the clearInterval function instead of setInterval in your code. This could potentially solve the issue.

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

Start DataTables TableTools using the DataTable function

I'm attempting to set up this apparently straightforward initialization process for the DataTables plugin feature called TableTools. From what I understand, all I need to do is specify the tableTools parameter and then initialize other options within ...

Utilizing JavaScript and jQuery to make a query to mySQL

Looking to solve a SQL database query challenge using JavaScript or jQuery? Here's the scenario: I have a SQL db and typically use the following query to retrieve data based on distance from specified coordinates: SELECT id, ( 3959 * acos( cos( rad ...

Learn the steps to extract and showcase targeted data from a JSON API!

Is there a way to retrieve and display the value of a specific variable from a JSON API array? For instance, suppose I want to show the current price of Bitcoin in USD within a particular WordPress post using coinmarketcaps JSON API ()? The JSON API prov ...

Using Jquery to Toggle Visibility of Question

Looking for help with this code: <!DOCTYPE html> <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"> </script> <script> $(document).ready(function(){ $(".btn1").click(function ...

Determine if the user's request to my website is made through a URL visit or a script src/link href request

Presently, I am working on developing a custom tool similar to Rawgit, as a backup in case Rawgit goes down. Below is the PHP code I have created: <?php $urlquery = $_SERVER['QUERY_STRING']; $fullurl = 'http://' . $_SERVER['SE ...

Is it possible to maintain a fixed footer while utilizing async/ajax functions?

Looking for a reliable solution to have a fixed footer that adjusts based on the page content? I've tested multiple samples, but they all fall short when it comes to incorporating AJAX elements. Is there a fixed footer out there that truly works seaml ...

Error occurred when attempting to send a POST request to the server using AJAX and data did

When I try to send form data using a POST request via AJAX, I am encountering an issue. The data being sent seems complete when I console it in the AJAX call, but on the server side, parts of the object appear to be missing and the data is getting cut off. ...

Create a separate server session specifically for handling an ajax request?

Currently, I am working with a collection of PHP server-side scripts that manage user session state by utilizing PHP sessions extensively for authenticated users. For the client side within a mobile application and using Jquery ajax, I am striving to esta ...

Transforming the current date() into a distinctive format, encompassing the utilization of T

Background In my Angular UI, I have a datepicker that is defined as: <date-picker name="contractEndDate" date="employee.contractEndDate"></date-picker> When the button is clicked, the contractEndDate value changes from null to the current da ...

how to use ajax to retrieve a value returned by a php function

I have two different files, one named index.php and the other called get_content.php. Strangely, I am unable to display anything on the get_content.php file. I am now left pondering where the issue might be - in index.php or get_content.php? To view the F ...

Guide on sending the API key to an API gateway through a request header with Jquery AJAX

I am facing an issue posting JSON data to an AWS API gateway that is protected by an API key. I managed to make the POST request successfully using Postman by adding the x-api-key header. However, I am struggling to achieve the same with JQuery code. How c ...

Jquery Ajax Finger gallery

After numerous days of scouring Google without success, I find myself at a loss. Uncertain if Stack Overflow is the appropriate platform for my inquiry, but here goes... Does anyone have recommendations for quality jQuery Gallery plugins that support ima ...

What is the process for implementing filtered HTML attributes in a directive?

I’ve created a custom directive that generates a popup menu by extracting data from HTML content. The purpose is to transform a group of Bootstrap carousel-compatible elements into a structured list. However, each .item element contains an attribute with ...

What is the purpose of using *//<![CDATA[* and *//]]>* in a jQuery code snippet?

Check out this JavaScript code snippet that I have: <script type="text/javascript> //<![CDATA[ jQuery(document).ready(function() { jQuery("#page_template option[value='sidebar-page.php']").remove(); }); ...

Why isn't my List<string> being retrieved from the MVC Controller in an $ajax request?

I am attempting to generate customized lists in my cshtml file through an ajax request. .ajax({ type: "GET", cache: false, url: "@Url.Action("getValidationLists")", contentType: "application/json", dataType: "json", ...

Using codeigniter and JQuery, I have developed a unique Javascript function to selectively extract a specific portion of text

I'm currently working with the following syntax: $("#orderbynumber").autocomplete( { source: "get_orders_by_order_number", messages: { noResults: '', results: function() {} }, select: function( event, ui ) { var select ...

The notify.js fails to display notifications in the event of an error

Why am I not receiving any error notifications even when there is an error message in the response object? $.ajax(settings).done(function (response) { if ( "error_message" in response ) { console.log(response); $.notify(" ...

Loading select list options asynchronously

I am working on extracting data related to Municipality names, ZipCodes, and more from a public service provider called DAWA using AJAX. Initially, I faced an issue with retrieving the data until I made the transfer asynchronous; hence, the function ajaxGe ...

Accessing the Angular scope and making modifications using Chrome browser

I need to access the $scope value in order to update its data values via a chrome extension. I have attempted to obtain the $scope using the code below: var $scope = angular.element(document.getElementById('name')).scope() While this code wor ...

Issue with Angular failing to identify jQuery after transferring the dependency from package.json to bower.json

Initially, my project included angular, angular-bootstrap, and jquery in the package.json file, with everything being compiled using browserify. // package "dependencies": { "angular": "~1.4.6", "angular-bootstrap": "~0.12.2", "jquery": "~2.1. ...