Troubleshooting issue with JQuery AJAX loading Bootstrap Dropdowns

I have a website on GitHub Pages that uses Bootstrap, but I'm having issues with the drop-down menu in the navbar. Sometimes it works and sometimes it doesn't. I am using $("#nav").load("url"); to load the navbar so that I can make changes and have them apply to multiple pages. The drop-downs work fine when I visit the page directly. You can view the webpage at

/resorces/navbar.html

<!DOCTYPE html>
<html lang="en">
    <head>

        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
        <!--bootstrap-->
        <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
        <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
        <!--main.css, i do not know if it is used on the page, i think not-->
        <link rel="stylesheet" href="http://scratchos.github.io/stylesheets/main2.css">
        <!--meta-->
        <meta charset="utf-8">
        <!--get url parameters for adding classes to set items to make it applicable to all pages-->
        <script>
            function getParameter(theParameter) { 
                var params = window.location.search.substr(1).split('&');
                for (var i = 0; i < params.length; i++) {
                    var p=params[i].split('=');
                    if (p[0] == theParameter) {
                        return decodeURIComponent(p[1]);
                    }
                }
                return false;
            }
        </script>
        <!--bootstrap dropdown code-->
        <script>
            $(document).ready = function () {
                $('.dropdown-toggle').dropdown();
            };
        </script>
    </head>

    <body>
        <!--bootstrap nav bar-->
        <div class="nav nav-tabs">
            <li id="home"><a href="#">Home</a></li>
            <li id="projects"><a href="#">My Projects</a></li>
            <li id="hfb">
                <!--JQuery-->
                <div class="dropdown">
                    <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown">Hungry-For-Blocks<span class="caret"></span></button>
                    <ul class="dropdown-menu">
                        <li id="hfb-home"><a href="//scratchos.github.io/Hungry-For-Blocks/">Home</a></li>
                        <li id="hfb-about"><a href="#">About</a></li>
                        <li id="hfb-doc"><a href="#">Documentation</a></li>
                        <li id="hfb-ins"><a href="#">Installation</a></li>
                    </ul>
                </div>
            </li>
            <li id="tut"><a href="#">Tutorials</a></li>
        </div>
        <!--script to apply the classes based on url params once page has loaded; it is done in this way because github does not support php:(-->
        <script>
            window.onload = function () {
                $("#" + getParameter("active")).addClass("active");
                if (getParameter("dis") !== false) {
                    $("#" + getParameter("dis")).addClass("disabled");
                };
            };
        </script>

  </body>
</html>

/stylesheets/main2.css

.nav a {
  color: #5a5a5a;
  font-size: 11px;
  font-weight: bold;
  padding: 14px 10px;
  text-transform: uppercase;
}

.nav li {
  display: inline;
}

.jumbotron {
  height: 500px;
  background-repeat: no-repeat;
  background-size: cover;
  color: #ff6600;
}

.jumbotron .container {
  position: relative;
  top: 100px;
}

.jumbotron h1 {
  font-size: 48px;  
  font-family: 'Shift', sans-serif;
  font-weight: bold;
}

.jumbotronm p {
  font-size: 20px;
}

.learn-more {
  background-color: #f7f7f7;
}

.learn-more h3 {
  font-family: 'Shift', sans-serif;
  font-size: 18px;
  font-weight: bold;
}

.learn-more a {
  color: #00b0ff;
}

.forum {
 padding: 20px; 
}

/index.html

<!DOCTYPE html>
<html lang="en">
    <head>
        <!--JQuery-->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
        <!--rendering script in css and jquery for the site, not relevant I think?-->
        <link rel="stylesheet" href="//scratchos.github.io/ScratchBlocks/scratchblocks2.css">
        <script src="//scratchos.github.io/ScratchBlocks/scratchblocks2.js"></script>
        <script>
            $(document).ready(function() {
                scratchblocks2.parse();
            });
        </script>
        <!--Bootstrap-->
        <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
        <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
        <!--main.css custom page CSS I don't think it is needed here as everything it formats has been omitted from this code?-->
        <link rel="stylesheet" href="http://scratchos.github.io/stylesheets/main2.css">
        <!--Set jumbotron background, probably an inefficient way of doing it?-->
        <style>.jumbotron{background-image:url('https://scratchos.github.io/images/jumbotron.png');}</style>
<!--Bootstrap metas-->
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <!--Title-->
        <title>-ScratchOs|Home</title>
        <!--Loading the navbar-->
        <script> 
            $(function(){
                $("#nav").load("http://scratchos.github.io/resorces/navbar.html"); 
            });
        </script>
        <!--Bootstrap dropdown code-->
        <script>
            $('#hfb a').click(function (e) {
                e.preventDefault()
                $(this).tab('show')
            })
        </script>

    </head>

    <body>
        <!--Navbar-->
        <div id="nav"></div>
        <!--The rest of the page is not included-->
  </body>
</html>

If you are able to fix the issue with the dropdowns, that would be greatly appreciated. Thank you :)

Answer ā„–1

Instead of directly embedding the code, I recommend using a separate JavaScript file called script.js. When you visit

http://example.com/menu/navbar.html
, everything functions properly. The issue arises because your website defaults to displaying the content of index.html but fails to show the code from navbar.html. An effective solution would be to create a shared script file that both pages can call upon.

Answer ā„–2

To resolve the issue, simply delete the plugins that are shared between the two pages.

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

Obtaining JSON data using Jquery results in the output of "undefined"

I am struggling to extract the correct values from a JSON document in order to display schedules in list view. Currently, when accessing the JSON document, I keep receiving "undefined" as the result. Below is an example of the JSON document: { "Ferries": ...

Is there a way to showcase Ajax data in an alert window and simultaneously integrate dynamically added data?

I am using a PHP script to fetch data in the following way: $.ajax({ url: './fetchData.php', type: "POST", data: { mail: mail }, dataType:'text', success: function(ans) { var data = JSON.parse(ans); $(' ...

Sending information from one ajax request to anotherORTransferring

Apologies for not including code in this post as I am currently working on a project in a car without internet access. Thankfully, I am using the amazing Stack Exchange app. Currently, I am facing a challenge where I need to work with two separate API cal ...

Mastering Interpolation in React with TypeScript is essential for creating dynamic and interactive UI components. By leveraging the

Incorporating and distributing CSS objects through ChakraUI presents a simple need. Given that everything is inline, it seems the main issue revolves around "& > div". However, one of the TypeScript (TS) errors highlights an unexpected flagging of ...

How to resolve CORS error when using custom request header in Django with JavaScript and redirecting to OPTIONS request?

I am currently working on building an API library using Django. This API will be accessed by javascript, with the Django-API and javascript running on separate servers. The Django API library requires a custom request header from the javascript front end, ...

The sluggish upload speed on Vimeo when using a library versus uploading directly

I have successfully integrated a library for uploading videos from my web app to Vimeo. Everything is working smoothly, but I am facing an issue with the upload speed. After running some tests, I noticed that the upload speed using the library is significa ...

Missing Home and Search icons on Jquery mobileNavigationBar

I am having an issue where the Home and search icons are not displaying properly in the output. Instead, they are showing up as hyperlinks. Can someone please help me with this? Here is the code I am using: <meta name="viewport" content="width=device ...

Listen to music on an Android device without disturbing anyone using an iPhone

I have an application built in Vue3 that plays a sound when a QR code is scanned. This feature works perfectly on Android and the web, but not when using the browser on iOS. I am struggling to identify the issue. Can anyone provide some insight? <qrco ...

"Can you provide guidance on displaying a form for a specific element based on its unique ID

I am trying to display the edit form when clicking on a specific image, but it is currently showing for all tasks. I need help in figuring out how to make it show only for one task. I attempted to use useState to change the boolean value "active" to show ...

Transferring data from a JavaScript variable to PHP using AJAX

Iā€™m currently working through the tutorial at http://www.w3schools.com/php/php_ajax_database.asp and I think I have a good grasp of how it all operates. This is my code: PHP: <?php include('./db.php'); $PM = mysqli_query($con, "SELECT DIS ...

issue with non-existent value in v-for loop when using functional template refs

Scenario I am currently developing a personalized filtering feature. This feature allows users to add n filters that are shown using a v-for loop in the template. Users have the ability to modify input values and remove filters as needed. Challenge Issue ...

Modifying icons with JavaScript

When I click on the play icon, it changes to the pause icon. However, I am only able to change the first icon from play to pause in my JavaScript code. How can I apply this functionality to all the audio elements on the page? let playIcon = "https://ima ...

How to initialize data in Vue.js components

I'm working on a Map.vue component and I need to update its data in Vue.js. However, I'm struggling to figure out how to do this: <template> <div> <div class="google-map" :id="mapName"> </div> </div> < ...

Ways to retrieve the most recent state in a second useEffect call?

Currently, I am encountering a situation where I have implemented two useEffect hooks in a single component due to the presence of two different sets of dependencies. My challenge lies in the fact that even though I update a state within the first useEffec ...

Is there a solution to resolving the type error that I am unable to identify?

I am attempting to implement a custom cursor feature in Vue 3, but unfortunately my code is not functioning as expected. Below you can find the code snippet I have been working on: <template> <div id="cursor" :style="cursorPoi ...

Utilize JQuery AJAX to retrieve a PHP array and then store it in a JavaScript variable

I am facing a challenge that seems simple to resolve, but it's proving to be quite tricky. Currently, I have a functional PHP file that fetches data from a database and stores it in an array. This file does not require any parameters and the output i ...

Issue with MUI toggle switch not updating display and value upon clicking once

I'm currently experiencing issues with a Material UI toggle switch in my project. Initially, when the component loads, the console log displays the correct value. However, when I toggle the switch from 'yes' to 'no', the visual cha ...

Event listener in JavaScript for Bootstrap 5 modal

Currently, I am utilizing Bootstrap v5.1.3 along with vanilla JavaScript, but it appears that I have misunderstood how to set up modal event listeners. Below is my current setup for two modals: var firstModal = new bootstrap.Modal(document.getElementById(& ...

The onClick event in HostListener is intermittent in its functionality

While attempting to create a dropdown box in Angular by following these examples, I am encountering inconsistent results. Below is the code I have used: HTML <button (click)="eqLocationDrop()" id="eqLocButton"><i class="fas fa-caret-down">< ...

Integrating a Find Pano functionality into a Kolor Panotour

I used a program called Kolor to create a panorama. Now, I am attempting to integrate the "find pano" feature, which involves searching through the panoramic images for display purposes. I have come across an HTML file that contains the search functionalit ...