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

Analysis of Alibaba Cloud CentOS7 server nginx configuration and FAQs

Preface: This article refers to jackyzm's blo...

Summary of Button's four Click response methods

Button is used quite a lot. Here I have sorted ou...

How to solve the error "ERROR 1045 (28000)" when logging in to MySQL

Today, I logged into the server and prepared to m...

Detailed analysis of several situations in which MySQL indexes fail

1. Leading fuzzy query cannot use index (like ...

XHTML Tutorial: XHTML Basics for Beginners

<br />This site’s original content, please i...

Solution to the failure of entering the container due to full docker space

Since the problem occurred rather suddenly and th...

Vue implements adding, displaying and deleting multiple images

This article shares the specific code for Vue to ...

10 Tips to Improve Website Usability

Whether it is a corporate website, a personal blo...

Let me teach you how to use font icons in CSS

First of all, what is a font icon? On the surface...

Docker installs Redis and introduces the visual client for operation

1 Introduction Redis is a high-performance NoSQL ...

Two simple menu navigation bar examples

Menu bar example 1: Copy code The code is as foll...

Ubuntu 15.04 opens mysql remote port 3306

Ubuntu 15.04 opens MySQL remote port 3306. All th...

Ubuntu boot auto-start service settings

How to create a service and auto-start it in Ubun...