logo
down
shadow

How to handle multiple fast jQuery ajax submissions


How to handle multiple fast jQuery ajax submissions

By : Rivers
Date : November 21 2020, 01:01 AM
With these it helps For a better user experience, I'd check the box immediately as the user clicks it, and let the request be sent to the server anonymously. Otherwise the user woul'd have to wait the round-trip time for visual feedback, which is generally not so great.
You can however easily implement a sort of queue:ing method that executes request "serially", like this. (warning untested)
code :
var queue = [];
var processing = false;

function queueRequest(data, cb){
    // Queue data to be send to the backend
    // Also cb will be called after it's done
    queue.push({
        data: data,
        cb: cb
    });
    processQueue();
}

function processQueue(immediate) {
    // If we have an empty queue, we are done!
    if (queue.length === 0) {
        processing = false;
        return;
    }

    if (!processing || immediate) {
        var item = queue.shift();   // Take first item
        processing = true;

        // Send the ajax  request
        $.ajax({
            url: "backend.com/checks",
            data: item.data,
            type: 'post',
            success: function(res) {
                if (typeof item.cb === "function")
                    cb(res);

                // Go on with the queue
                processQueue(true); // We call ourself, so it's "immediate"
            }
        });
    }
}
queueRequest({checkbox:5}, function(res){
    // Check the checkbox here, or do w/e you want
    // ...
});


Share : facebook icon twitter icon
How to handle multiple submissions server-side

How to handle multiple submissions server-side


By : Aaron Powell
Date : March 29 2020, 07:55 AM
this will help One really effective way is to submit a token along with the request, and keep a list of used tokens. If the token is not valid, or the token has already been processed, then abort.
The token can be as simple as an incrementing integer, stored in a hidden text field, or you can encrypt it to increase security. This feature can be made more robust by generating the token when the page is created, encrypting it, then confirming the token has been generated AND has not been processed.
Submitting a form with JQuery Ajax results in multiple requests (and submissions)

Submitting a form with JQuery Ajax results in multiple requests (and submissions)


By : user2225466
Date : March 29 2020, 07:55 AM
I wish this helpful for you Each time you click the button, the code is calling your function. In that function the line $(formId).submit(...); is binding the event to the form's submit action. This happens every time you click, adding multiple "submit" events to the form. You need to unbind the action first. So you could call $(formId).unbind('submit').submit(...); instead.
Ajax submissions with jquery in rails not working

Ajax submissions with jquery in rails not working


By : user3308578
Date : March 29 2020, 07:55 AM
like below fixes the issue I see 2 things right on top. First you are not specifying where the form is sent to. So you need to change that to
code :
<%= form_for @comment, :url => {:controller => :comments, :action => :create}, :remote => true do |f| %> 

    <% if signed_in? %>

    <%= f.label :author %>
    <%= f.text_field :author, :value => current_user.name %>

    <% else %>

    <%= f.label :author %>
    <%= f.text_field :author %>

    <% end %>

    <p><%= f.label :content %><br />
    <%= f.text_field :content %></p>

    <p><%= f.submit %></p> 
<% end %> 
match "comments/create" => "comments#create"
MVC4 Jquery / UI / Ajax Release Build breaks my form submissions?

MVC4 Jquery / UI / Ajax Release Build breaks my form submissions?


By : Joellyn
Date : March 29 2020, 07:55 AM
it should still fix some issue Well I found out what the answer was......Talk about a perfect storm....
I was using JQuery 1.9.1. Apparently the recent versions of JQuery cause "bundling" to break.....
Prevent multiple ajax submissions on multiple clicks

Prevent multiple ajax submissions on multiple clicks


By : user2522483
Date : March 29 2020, 07:55 AM
wish of those help I've a WordPress blog running this jQuery code that allows users to click a bookmark link that saves the post as a bookmark. Each post shows a total bookmark counter that looks like: "Bookmarked (5)". Although this code works, it registers multiple clicks whenever someone clicks multiple times on the bookmark link and then saves the same post as multiple bookmarks. When the user tries to remove the bookmark by clicking on the bookmark link again, it registers multiple clicks again and the counter starts showing minus numbers which looks like: "Bookmarked (-5)". , One way is to add a .disabled class to your link before the $.post().
code :
// Before ajax...
if ($(this).hasClass('disabled')) {
    return false;
} else {
    $(this).addClass('disabled');
}
// Make sure we refer to the same element
var that = this;

// On post success...
$(that).removeClass('disabled');
Related Posts Related Posts :
  • How to change add and remove active class in JavaScript
  • how to toggle a specific div in javascript
  • How to get all the values from multiple keys of an array of object?
  • jQuery bind() unbind() and on() and off()
  • regular expression to find DD Month YYYY from a string
  • How to upload files from web client (HTML/jQuery form) to your Dropbox folder
  • Backbone history and require.js issue
  • Confusion over Classical and Prototypal Inheritance Javascript
  • How to take screen shot of current webpage using Javascript/JQuery?
  • Store meridiem in a variable
  • class declared inside closure vs standard class without closure
  • javascript confirm box always return true
  • dynamically changing the size of font size based on text length using css and html
  • Node.js - Getting the host IP address while on Amazon EC2
  • Confusing CSS, can anyone explain please
  • How to install v8-profiler on Windows 8 (64 bit) using npm?
  • Resolve promise based on another promise
  • google maps adding overlay layer above UI and markers
  • Style specific letter?
  • RangeError: Maximum call stack size exceeded with array.slice
  • node rest client get with local variable
  • If condition not executes while mouse move fastly
  • Count the number of displayed elements in a HTML list
  • Locate JavaScript source code in Emacs
  • Clean, Modular Code vs MV* Frameworks
  • infinite scroll without loading image
  • Backbone: reverse collection order with comparator
  • What do printers ignore?
  • jQuery UI .tabs() Contentless tab?
  • Execute Javascript alert() after page (visually) loaded
  • JavaScript - duplicating array doesn't work
  • Excessive clickable area below image
  • JavaScript Regex: Replace |b| with <b>
  • Unexpected value change in 2D array in JavaScript
  • Function doesnt see parameter as a array of objects
  • jQuery fetch keypress event on chrome and IE
  • How to enable jquery validate localization?
  • Cassandra map collection returned by node.js Helenus looks odd
  • angular ng-repeat with multiple filter options
  • Selecting Children without ID or Class names
  • How to uncheck a group of checkboxes when another checkbox is checked
  • Is hiding content by Javascript or jQuery Worth trying
  • Load XUL resource using javascript
  • XML to HTML text area from server file system
  • set focus() on textbox on form onload
  • es lint '' is assigned a value but never used' eventhough i have used it
  • Can "name" attribute be used for custom VueJS components
  • Get innerHTML of content when it is clicked
  • HTTPS causes CSS animations to not load? Very confused
  • How to hide other div apart from touched div to the band
  • Is global variable assignment atomic on NodeJS?
  • Datepicker onchangemonthyear beforeshowday
  • trying to render html files using jade but it still adresses it as a jade
  • Google Analytics - Understanding and Dissecting the Snippet: What is | | [ ];
  • Replacing "[aA09.b]." to "[aA09.b]\n" in in JavaScript
  • Why wrap a function definition in an immediate function?
  • Enable / disable jQuery script on switching to different tab in a HTML page
  • how can find return variable value outside anonymous function in node js mysql query function
  • Converting 1 to 0001 in javascript array
  • svg viewbox should not resize the text fontSize?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org