If you submit the data repeatedly, the data will be accumulated in the data table. Is there a solution? If you submit the data repeatedly, the data will be accumulated in the data table. Is there a solution?
Reply content:
If you submit the data repeatedly, the data will be accumulated in the data table. Is there a solution?
Post/Redirect/Get
PRG is a Web design that prevents repeated data submission.
Server:
1. Add a form token to verify that the token passed is invalid.
2. If a field must be unique, set a unique field in the database.
3. The session stores the last part of the submitted data and determines whether the data is consistent.
4. Go to the new page after the operation is successful.
JS end:
1. After submission, cancel the submission event or set it to not clickable.
2. After the operation is successful, reload the page.
Set the field to UNIQUE in the database, and the PHP insert statement will encounter repeated execution errors. If you catch the errors, you will know that the insertion failed.
After Ajax is submitted, set submit to not clickable
Set a unique index for the database to prevent repeated data
The method is as follows. For more information, see comments.
Var tag = 0; $ ('. xxx '). on ('submit ', function () {// only when tag = 0 Can the submitted event be executed if (tag = 0) {// the first time the submitted event is executed, change the tag value so that when the submit is triggered again, no behavior will be performed for tag = 1; // do something // You can also restore the tag value to 0 when some conditions are met, so that the event can be executed again }})
Click Submit time. After the return result is successful, the content in the form is cleared. This avoids repeated submission.
Refer to laravel csrf-token https://laravel.com/docs/5.1/routing#csrf-x-csrf-token
Frontend
It seems that bootstrap or jquery has a button method.
For example, you can add a data attribute on the button.
Submit
Js:
$ ('# Submit'). button ('submit '). on ()
In this way, the button is automatically disable and the text of data-submit is displayed.