Have you ever seen a bad layui form submit twice?

preface

I have been using this layui for almost two years, and I just built a new xadmin framework, so there is the problem that forms will be submitted repeatedly. I am very upset!

If you want to get straight to the solution, go straight to section 3.

First, the initial operation

First let’s see what kaka does.

Using the Xadmin template, it is estimated that the JS file is not fully caused by the problem.

The effect that kaka wants to achieve is shown below.

Realize the effect picture one
Realize the effect diagram two

This is the effect that has been realized, which is not available before, because of the fruit caused by adding this thing.

I don’t know how you usually develop to find the code, kakaka is directly to the code library edge directly search link format is not correct.

The following is the result of the click search, so the next is to introduce this JS file to try!

Required JS file

So I pick up the keyboard and I import this file

Import js files

These are the consequences of the original!

Second, problems recur

Add a piece of data

Add data

Sure enough, there were two pieces of data, ha ha! Meng to force the

Returns the result

Third, solve the problem

In fact, this problem is caused by carelessness, and is still not familiar with the Layui framework.

The solution is to kill the form js file. Very funny.

Js file

When you open the layui.js file, the penny drops

It turns out that layui.js automatically contains modules, which I added locally, so this happens.

Layui. Js file

Of course, the problem is not just ka-ka.

If you reference layui.all.js file twice in a row, it will trigger twice in a row, or if you reference layui.all.js file first and then reference layui.js file, it will trigger twice, please check your reference file carefully!!

After referring to the layui.all.js file, the layui.js file is referenced again, causing two consecutive fires!

Adhering to learning, blogging and sharing is the belief that Kakha has been upholding since she started her career. I hope the articles on the Internet can bring you a little help. I’m Kaka. See you next time.