I haven't written JS code for a long time and just encountered such a problem. Most forms in our system are not done to prevent duplicate submissions.
Since you don't want to process it on the backend, if it is processed by the backend, you need to give a one-time token value when the page is loaded. Not only does it increase the development workload, it is also easy to forget to do this. At the same time, ajax is not easy to process. If you need to submit it, you will return a new token value at the same time.
So I want to do it on js. In fact, I mentioned it to the front end before, but there was no movement for a long time, so I had to get a brick and throw it out. The idea is to overwrite $.ajax, and solve the problem of preventing duplicate submissions here , while the front-end business development will not be affected, the code will not be changed, and there will be no perception.
I think one of the purposes of the architecture is to simplify business development, block out business-independent details, and allow front-line development to write business with peace of mind.
The code is as follows:
/*** Created by xiayongsheng on 2016/6/12.*/;(function($){var ajax = $.ajax;// Requests used to store ajax var ajaxState = {};var kinhomAjax = function () {var args = Array.prototype.slice.call(arguments, 0);// The url data is consistent, // The url should be taken out, the data should be sorted by key values, and then the values are spliced together, and the value obtained by sha1 is used as fingerprint // Use url as fingerprint first var hash = typeof args[0] === 'string'?args[0]:args[0].url;if (typeof ajaxState[hash] !== 'undefined') {if (ajaxState[hash] > 3) {alert('Please do not submit repeatedly, the request is being processed');}++ajaxState[hash];return $.Deferred();}ajaxState[hash] = 1;var def = ajax.apply($,args);def.done(function () {delete ajaxState[hash];});return def;};$.ajax = kinhomAjax;})(jQuery);The above is the relevant knowledge about how to prevent repeated submissions from JS Ajax requests introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!