Home > Web Front-end > JS Tutorial > Sharing detailed examples of the use of jQuery.form.js

Sharing detailed examples of the use of jQuery.form.js

小云云
Release: 2018-01-10 09:13:09
Original
1865 people have browsed it

Faced with the problem: After the form is submitted, the backend will return prompt information. However, the native HTML cannot obtain the data returned by the backend, resulting in such a situation: after submission, the page jumps, and the json data returned by the backend is displayed on a blank page, and the user experience is 0 points. This article mainly shares with you the use of jQuery.form.js, hoping to help everyone.

Solution: Use jquery.form.js

Steps

Customize the control submission function

var submitChange=function () {
    $("form").ajaxSubmit(function (message) {
      alert(message.text);
      window.location.href="/index" rel="external nofollow" ;
    });
    return false;
  }
  //这个函数一是处理了后端返回的数据,二是返回了一个false,阻断了原生submit事件的发生。
Copy after login

Transform the form form (add onsubmit event, return from Define the processing function)

<form action="/do" onsubmit="return submitChange();">
</form>
Copy after login

Finally

Be careful to import the Js file!

For example:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.form/4.2.1/jquery.form.min.js" integrity="sha384-tIwI8+qJdZBtYYCKwRkjxBGQVZS3gGozr3CtI+5JF/oL1JmPEHzCEnIKbDbLTCer" crossorigin="anonymous"></script>
Copy after login

Related recommendations:

jquery DataTable front and backend dynamic paging implementation method sharing

jquery loading Single file vue component method sharing

jquery click on the text content to enlarge and center the example sharing

The above is the detailed content of Sharing detailed examples of the use of jQuery.form.js. 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