Home>Article>Web Front-end> Detailed explanation of how to prevent the page from jumping when the Form form is submitted in HTML

Detailed explanation of how to prevent the page from jumping when the Form form is submitted in HTML

黄舟
黄舟 Original
2018-05-26 16:32:23 21632browse


1.1 Solution 1
Form action submits data, but the page does not jump. You can use Iframe to solve this problem.
Example:

    Form提交表单页面不跳转 

Note: The target attribute of the Form element must be the name attribute of the iframe element that specifies the return result.
Iframe elements can be placed anywhere in the body or in form elements.

1.2 Use Ajax to implement, no refresh technology
Use javascript to directly read the value of the input element, and then put it into the variable in the function for ajax to process.
Example - js serialize or serializeArray method to serialize form data:

First name:
Last name:
$("#btn").click(function(){ var x=$("form").serializeArray(); console.log(x); //执行结果:[{name: "FirstName", value: "Bill" },{name: "LastName", value: "Gates" }] var y=$("form").serialize(); console.log(y); //执行结果:FirstName=Bill&LastName=Gates });

Note: The serializeArray() method will return a json value, and serialize () method will return a string value.

The above is the detailed content of Detailed explanation of how to prevent the page from jumping when the Form form is submitted in HTML. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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