Analysis of two usages of the a tag in HTML post request

Analysis of two usages of the a tag in HTML post request

Two examples of the use of the a tag in HTML post request are as follows:

1. Use ajax to initiate a POST request

The HTML code is as follows:

<a href="https://www.jb51.net/" class="a_post">Initiate POST request</a>

The JQuery code is as follows:

$(".a_post").on("click",function(event){
    event.preventDefault(); // Make the method of a invalid, that is, it cannot be adjusted to the URL in href (https://www.cnblogs.com/)
    $.ajax({
           type: "POST",
           url: "url address",
           contentType:"application/json",
           data: JSON.stringify({param1:param1,param2:param2}), //parameter list dataType:"json",
           success: function(result){
              //Operation after request is correct},
           error: function(result){
              //Operation after request failure}
    });
});

2. Use form to initiate POST request

<form id="_form" method="post" action="target">
  <input type="hidden" name="name" value="value" /> 
  <a onclick="document.getElementById('_form').submit();">Click Submit</a>
</form>

Summarize

This is the end of this article about the two usages of the a tag in html post request. For more relevant content about the a tag in html post request, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

<<:  Various ways to modify the background image color using CSS3

>>:  Introduction to network drivers for Linux devices

Recommend

Open the app on the h5 side in vue (determine whether it is Android or Apple)

1. Development environment vue+vant 2. Computer s...

MySQL database table partitioning considerations [recommended]

Table partitioning is different from database par...

The implementation process of ECharts multi-chart linkage function

When there is a lot of data to be displayed, the ...

Test and solution for MySQL's large memory usage and high CPU usage

After the changes: innodb_buffer_pool_size=576M -...

Bootstrap realizes the effect of carousel

This article shares the specific code of Bootstra...

Windows DNS server exposed "worm-level" vulnerability, has existed for 17 years

Vulnerability Introduction The SigRed vulnerabili...

Detailed explanation of JavaScript progress management

Table of contents Preface question principle test...

vue.js downloads pictures according to picture url

Recently, when I was working on a front-end vue.j...

React Diff Principle In-depth Analysis

Table of contents Diffing Algorithm Layer-by-laye...

Understand the initial use of redux in react in one article

Redux is a data state management plug-in. When us...

jQuery implements the function of adding and deleting employee information

This article shares the specific code of jQuery t...

Summary of some common methods of JavaScript array

Table of contents 1. How to create an array in Ja...

Let's talk about the v-on parameter problem in Vue

Use of v-on:clock in Vue I'm currently learni...

30 free high-quality English ribbon fonts

30 free high-quality English ribbon fonts for down...