How to solve layui form submission twice

咔咔
Release: 2020-12-28 13:36:06
Original
2675 people have browsed it

The bad layui form will be submitted twice, have you encountered it?

##Preface

I have been using this layui for almost two years. I just built a new xadmin framework, so the problem of repeated submission of forms appeared. Very upset!

If you want to know the solution directly, just go to the third section.

1. Initial operation

First let’s take a look at what operations Kaka did.

The xadmin template used is probably a problem caused by not fully importing the js file.

The effect Kaka wants to achieve is as shown below.

How to solve layui form submission twice
Implementation effect picture one
How to solve layui form submission twice
Implementation effect picture two

This is the effect that has been achieved, before it was No, it's just the result of adding this thing.

I don’t know how you usually find the code for development. Kaka directly goes to the code library and searches directly The link format is incorrect.

The picture below is the result of Kaka search, so the next step is to introduce this js file and try it!

How to solve layui form submission twice
Required js file

So I picked up the keyboard and imported this file into it

How to solve layui form submission twice
The imported js file

is the original cause of the problem!

2. Reproduce the problem

Add a piece of data

How to solve layui form submission twice
Adding data

did not disappoint, two pieces of data appeared, haha! Confused

How to solve layui form submission twice
Return results

3. Solve the problem

actually appears This problem is caused by carelessness, and still unfamiliar with the layui framework.

The solution is to kill the form js file. Isn’t it funny? Yes! Very funny.

How to solve layui form submission twice
js file

You will suddenly realize when you open the layui.js file

It turns out that layui.js automatically includes all modules I imported the module locally, so this happens.

layui.How to solve layui form submission twice
layui.js file

Of course the problem is not just the case of Kaka.

If you reference the layui.all.js file twice in a row, it will trigger twice in a row, or reference the layui.all.js file first, and then reference the layui.js file and it will trigger twice. Please be careful. Check the files you reference!!!

After referencing the layui.all.js file, layui.js is referenced again, causing it to be triggered twice in a row!

Persistence in learning, persistence in blogging, and persistence in sharing are the beliefs that Kaka has always upheld since his career. I hope that Kaka’s articles on the huge Internet can bring you a little help. I am Kaka, see you in the next issue.

The above is the detailed content of How to solve layui form submission twice. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!