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

How to set up the use of Chinese input method in Ubuntu 18.04

In the latest version of Ubuntu, users no longer ...

How to use cookies to remember passwords for 7 days on the vue login page

Problem Description In the login page of the proj...

Summary of Problems in Installing MySQL 5.7.19 under Linux

The first time I installed MySQL on my virtual ma...

Tutorial on installing php5, uninstalling php, and installing php7 on centos

First, install PHP5 very simple yum install php T...

Summary of data interaction between Docker container and host

Preface When using Docker in a production environ...

MySQL 5.7.15 version installation and configuration method graphic tutorial

This article shares with you a detailed tutorial ...

A brief discussion on logic extraction and field display of Vue3 in projects

Table of contents Logical Layering Separate busin...

How to avoid data loop conflicts when MySQL is configured with dual masters

I wonder if you have ever thought about this ques...

How to find the my.ini configuration file in MySQL 5.6 under Windows

Make a note so you can come back and check it lat...

Mysql method to copy a column of data in one table to a column in another table

mysql copy one table column to another table Some...

Practical record of solving MySQL deep paging problem

Table of contents Preface Why does limit deep pag...

The implementation principle of Mysql master-slave synchronization

1. What is MySQL master-slave synchronization? Wh...

js to achieve cool fireworks effect

This article shares the specific code for using j...

How to operate Docker and images

Find mirror We can search for images from the Doc...