Webpack double fires its function

I have implemented a feature on my website where an HTML page is loaded using AJAX without refreshing the entire page. Everything seems to be working correctly, but I have noticed that whenever the AJAX page is loaded, it triggers the webpack function twice.

Here is the HTML code:

<html lang="en" class="page"><head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link href="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d2b0bdaabbb1bdbca192e0fce2fce5">[email protected]</a>/css/boxicons.min.css" rel="stylesheet">
  <link rel="stylesheet" href="index.css">
  <title>Document</title>

</head>
...

The second HTML page follows a similar structure as shown above.

<html lang="en" class="page"><head>
 <meta charset="UTF-8">
 ...
</body></html>

The webpack index.js file contains the following code:

async function getAccount() {
    const accounts = await ethereum.enable();
    const account = accounts[0];
    // do something with new account here
    
    numberLoadeds++;
    
...

ethereum.on('accountsChanged', function (accounts) {

    getAccount();

});

This is the webpack configuration file:

const path = require('path')

module.exports = {
    mode : 'development',
   entry: './client/index.js',
   output: {
      path: path.resolve(__dirname, 'public'),
 ...
}

I suspect that the functions are being duplicated when the AJAX function changes the page, but I am unsure how to verify or troubleshoot this. Any assistance would be greatly appreciated. Thank you.

Answer №1

We encountered a problem related to the HTML file itself. During the execution of the jQuery AJAX function, both the div element and the script were sent without the proper script tag. As a result, when this content was received by the browser, it could not properly interpret the script. This led to duplication issues as jQuery instructed the browser to evaluate the received script.

The solution turned out to be moving the script tag to the header section and eliminating the script filter from the data being sent in the AJAX request.

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

Angular JS may encounter a cross domain problem when attempting to post on a third-party website

HTML Code: <div ng-app="myApp" ng-controller="myController"> <div> <input type="button" data-ng-click="submit()" ...

Using PHP to filter data using $_GET variables?

https://i.sstatic.net/vDqe3.png In order to sort the small divs based on specific filters like AB Main Hall, AB Club, Huis 23, I believe using $_GET is necessary. Here is the code snippet I currently have. <?php $concert = [ [ "datum" =& ...

Tips for transforming a JSON object into a JavaScript array, and specifically filtering it based on a key

I am receiving a JSON object through an Ajax request with the following keys and values: [{"App_Name":"Maccy D's","ID":2017},{"App_Name":"B King","ID":2011}] I want to convert this object into a JavaScript array where each App_Name and ID value is c ...

I am facing an issue where the inline CSS is not being applied in my

I recently integrated tcpdf in my CodeIgniter project and encountered an issue with applying inline CSS to td. This is a snippet of my code: <table style="float:left;width:100%; border:1px solid #c2c2c2; margin-top:10px;"> <tr style="float:l ...

JavaScript is currently not executing properly. According to Firebug, the message states to "reload the page to obtain the source for: ..."

I'm currently working on creating a bookmarklet that adds some JavaScript elements to the head of a webpage. However, I've noticed that one of them is not loading properly. Is there a solution to this issue? Is it possible to reload the page wit ...

Toggle the class of a div when clicked and then change the class of another div

In my website, I have a site overlay Div (#site-overlay) that is currently set as display:none. I am looking to change the class to block when I hover and click on the menu buttons. I can use both vanilla JavaScript and jQuery to achieve this. The menu it ...

After performing an action with Redux, the error message ""Cannot access properties of 'undefined'" is displayed

I am currently developing a Shopping List App using React/Redux. I am facing issues with removing items from a list. When I trigger the 'removeItem' action, the page no longer recognizes the object that represents the list (which was originally s ...

What methods can I use to ensure a jQuery dialog stays visible at all times?

To avoid centering the dialog on the screen, I am specifying the top and left coordinates of the box. The positioning is set up so that it aligns next to a link without being open until clicked. $("#error").dialog({ bgiframe: true, autoOpen: false ...

What's the best way to add a suffix to a dynamic counter animation?

Having trouble adding a static suffix to the end of animated counters. I want to include a "+" sign in some of them without animation. I attempted to create a suffix class, but it doesn't append directly to the end value - it keeps showing up below t ...

I am in need of a efficient loader for a slow-loading page on my website. Any recommendations on where to find one that works

I'm experiencing slow loading times on my website and I'm looking to implement a loader that will hide the page until all elements are fully loaded. I've tested several loaders, but they all seem to briefly display the page before the loader ...

Utilize the ng-controller directive with unique aliases across various sections of HTML code

I'm facing an issue with my ng-controllers when multiple controllers are used on the same page. For instance, I have one controller in the page header, another in a different section of the same page, and one in the content of the page. However, all o ...

What is the best way to personalize Material UI elements, such as getting rid of the blue outline on the Select component?

Embarking on my journey of developing a React app, I made the decision to incorporate Material UI for its array of pre-built components. However, delving into the customization of these components and their styles has proven to be quite challenging for me ...

Conceal and reveal dropdownlist options within a gridview

Is there a way to prevent my dropdown list in gridview from displaying the same selected item, except for "Please Select"? The dropdown is within a gridview and the list items are generated in the code behind. For example, if 1 is selected, all other dropd ...

Check out this awesome jQuery Image Hover Plugin that allows you to create dynamic animations when hovering over other elements

Is it possible to use Adipolo in a way that allows hovering over a different element for the image animations to work? Currently, I am using the following code: $('#img-caption-one').adipoli({ 'startEffect' : 'grayscale' ...

When a radiobutton is clicked, a jQuery call to a PHP function triggers an AJAX request which results in a JavaScript function becoming unrefer

Currently, I have a situation where two radio buttons are representing different products. When one of them is clicked, the goal is to update the price displayed on the website based on the selected product. Everything seems to be working fine when using t ...

What is the best way to ensure that third tier menus open in line with their respective items?

Check out this fiddle link: http://jsfiddle.net/Wss5A/72/ Focusing on the following: 2-A-1 2-A-2 2-A-3 The third-tier menu is currently displayed starting from the top left corner. I want the first submenu element to be aligned with either 2-A-1, 2-A- ...

Activate a specific component of hover effect within multiple components generated by the `v-for` loop

Hey there! I'm currently facing a CSS challenge related to Vue. Let's say I want to display multiple components using v-for, and I want to add a hover effect to each component individually. The goal is to have the hover effect only apply to the c ...

Resolved: Flask route failing to receive Ajax request

I am encountering an issue while attempting to gather 2 inputs from my HTML Form and send them to my @app.route("/sell") using Ajax. Despite following the same method for other routes without any problems, I seem to be facing a unique challenge this time. ...

Tips on attaching the main element of a partial view

I have a scenario in my ASP.NET MVC project where I need to render a partial view once in the main view, and then upon clicking the add button, I want to append the entire partial view to the form. However, when I click add, only the child element is added ...

Apache causes HTML download tag to malfunction

I have an HTML file that includes the following code: <a href="/Library/WebServer/Documents/file.zip" download="file.zip"> Download here </a> When I test this HTML page on Chrome, it successfully allows me to download the file. However, when ...