Avoidance of duplicate entries

I am currently experiencing issues with double submissions on my local website. Many of my users have slow internet connections and tend to double-click the submit button. I implemented a disable button event in my AJAX code, but it doesn't seem to work properly on slow connections.

Here is the code snippet I used:

 $.ajax({
    url: 'submit-application-fee-details.php',
    method: 'POST',
    dataType: 'TEXT',
    data: {applno : applno, feecode : feecode, feeamt : feeamt, auditky : auditky, uid: uid, feepd : feepd, dedto : dedto},
    beforeSend: function(){
        document.getElementById("confirmsubmit").disabled = true;
        document.getElementById("confirmsubmit").innerHTML = 'Submit &nbsp; <div class="spinner-border text-light" role="status"> <span class="sr-only">Loading...</span></div>';
    },
    success: function(response) {
       if(response == 'Approved Application' || response == 'Updated' || response == 'Inserted'){
            document.getElementById("update").classList.add("button-hidden");
            document.getElementById("cancel").classList.add("button-hidden");

            initialize_form();
            display_table();
            clear_fee_info_form();

            $('html, body').animate({
                scrollTop: $("body").offset().top
            }, 100,
            'linear');

            if(response == 'Approved Application'){
                show_alert('Fee Submit', "Application is approved. Details cannot be updated.", 'warning');
            }
            else if(response == 'Updated'){
                show_alert('Fee Submit', "Fee has been updated.", 'success');
            }
            else if(response == 'Inserted'){
                show_alert('Fee Submit', "Fee has been assigned.", 'success');
            }
        }
        else{
            show_alert('Fee Submit Error', response, 'error');
        }
    },
    complete: function(){
        $('#confirmModal').modal('hide');

        document.getElementById("confirmsubmit").disabled = false;
        document.getElementById("confirmsubmit").innerHTML = 'Submit'; 
    }
});

In my AJAX function, I included a beforeSend method that disables the button before sending the data and enables it after inserting the data. However, when users with slow internet connections access the site, the button does not always disable as intended. Is there a more effective way to prevent this issue?

Answer №1

Prior to making the ajax call, it may be beneficial to execute the disabled = true code. This could potentially address any delays caused by network resolution or other issues during the beforeSend stage.

Another approach is to set up a global boolean variable in JavaScript that can act as a lock to prevent multiple ajax calls.

It is recommended to implement these measures before initiating the ajax request.

Additional Note: Please note that if the submit button on the form is disabled, users may still be able to bypass this restriction by pressing Enter in certain areas.

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

Strange audio issues encountered in Internet Explorer 11

Incorporating HTML5 Audio into a website project for background playback during specific events is my current endeavor. An unusual occurrence has been identified with Internet Explorer failing to load audio from one of my web domains. To illustrate this i ...

The jQuery .load method is having trouble loading a local HTML file within a Cocoa WebView

Having an issue with my Cocoa WebView where I'm attempting to load a local HTML file using jQuery.load(). My code snippet looks like this: $("#mydiv").load("test.html"); // The test.html file is located within the app's bundle Although no exce ...

"Animating an HTML element to track the movement of the mouse pointer

I'm currently working with an html element that looks like this: <img src="./pic/char.png" width="30" height="30" alt="me"> I'm wondering if anyone knows how to make this html element move towards the cursor using javascript. Any help wou ...

PHP - Offline/Online Status Polling Protocol Guide for Beginners

I am in search of a solution to track the online and offline status of users on my website. My site is a single page with no clickable links, so users may leave their tabs open for long periods without interaction. It is not essential to pinpoint the exact ...

Having trouble executing `npm start` command

After running npx create-react-app and then npm start, I encountered an error message https://i.sstatic.net/Uj5EC.png. Despite following the suggested solutions, the error persists. Any idea why this is happening? ...

Utilizing ngRepeat to build intricate rows within a table

I have a unique collection that appears as follows: { "10": {}, "12": { "20": { "value": 1, "id": 1, }, "100": { "value": 12, "id": 1, } }, "14": { "10 ...

UserControl with AjaxToolkit Pop-up Feature

I am experiencing an issue with my page that contains a user control. Within the user control, I am utilizing an AjaxToolkit popup window to load a div. Everything works as expected when the page is loaded for the first time and IsPostBack is false. Howeve ...

The error message "bind is not defined in chat.js on line 89 in React js" appears due to a ReferenceError

Greetings! I am new to working with React JS and have encountered an error in my code while developing a project. The console shows the following message: chat.js:89 Uncaught ReferenceError: bind is not defined(…) I am struggling to identify where I ...

What is the most effective method for implementing multiple textures in three.js?

After recently transitioning to three.js as my renderer, I am eager to establish a texture mapping system. However, determining the best practice for this task is a bit uncertain for me. Here is the scenario I am dealing with: My levels consist of numero ...

Struggling to convert a JSON file into a TableView within a JavaScript application developed with Appcelerator

Trying to display a JSON file in a table using JavaScript and Appcelerator is proving to be quite a challenge. The output appears as an empty table when compiled to an example page. As someone relatively new to JavaScript and JSON, I'm seeking guidanc ...

Bidirectional binding of form input directive using isolated scope

Currently, I am diving deep into AngularJS and focusing on mastering directives. My goal is to create a form input directive that can be easily reused across all my forms, simplifying the repetitive markup that comes with each form. However, I am facing a ...

What steps can I take to ensure that my keyup function is not delayed by one character?

Whenever I type something in my textarea, I want the text to instantly display in my result box. I've tried using both the keyup and keydown functions, but I'm facing an issue where there is a delay of one character when typing quickly. For exa ...

Guide on integrating a Jison generated parser within an Angular application

Using the Jison library, parsers can be created based on a specific grammar by running: $ jison calculator.jison This process is described in reference [1]. The above command generates a parser named calculator.js. Now the question arises - how to in ...

What is the process of transforming an Angular object that includes nested child objects and arrays?

I'm currently working on an Angular project and I am looking for a way to extract and modify the formData before sending it to the server as JSON. Here is the original data: { "BioData":{ "firstname": "Greg", " ...

Clicking with jQuery to float left and then bringing back

I have written this JavaScript code that is supposed to float the address div to the center when you click on the info panel using the "addressmoved" class. Challenges However, when I click on the trigger button, instead of the address div moving to the ...

Angular not detecting changes in string variables

Issue with variable string not updating var angulargap = angular.module("angulargap", []); angulargap.factory('cartService', function($rootScope,$http){ var fac ={ message:"factory", getCart:function(call){ $h ...

Leveraging jQuery's $.getJSON method to fetch localization data from aprs.fi

Utilizing JSON to retrieve localization coordinates from is my current goal. I came across an example on http://api.jquery.com/jQuery.getJSON: <script> $.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?", { tags: ...

removing a database row with the combination of Node.js, MySQL, Express, and vanilla JavaScript

I am currently in the process of developing a basic application using node, express, and mysql. My goal is to establish a route that allows me to delete a specific row from my database. Initially, I attempted to achieve this through a pure javascript xhr ...

Display information in real-time based on user input using Highcharts

I am trying to display data using highcharts on my index.php page. Can anyone help me with this?, here is what I have attempted so far: This is the HTML code I have: <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" cont ...

Store and retrieve user input using JavaScript or JSON

Can someone please assist me in finding a solution to this problem? I have 3 input fields where users can type in their answers. There is also a "SAVE" button that allows users to download their input values into a file.txt. Additionally, there is a "choos ...