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

CSS to achieve Tik Tok subscription button animation effect

I was watching Tik Tok some time ago and thought ...

Complete steps to install MySQL 8.0.x on Linux

MySQL Introduction to MySQL MySQL was originally ...

How to add vim implementation code examples in power shell

1. Go to Vim's official website to download t...

How are Vue components parsed and rendered?

Preface This article will explain how Vue compone...

Measured image HTTP request

Please open the test page in a mainstream browser...

Analysis of Sysbench's benchmarking process for MySQL

Preface 1. Benchmarking is a type of performance ...

Vue SPA first screen optimization solution

Table of contents Preface optimization SSR Import...

HTML basics summary recommendation (paragraph)

HTML Paragraph Paragraphs are defined by the <...

JS calculates the probability of winning based on the prize weight

Table of contents 1. Example scenario 1.1. Set th...

Three ways to parse QR codes using javascript

Table of contents 1. Use JavaScript to parse the ...

Practical explanation of editing files, saving and exiting in linux

How to save and exit after editing a file in Linu...

Detailed explanation of the Docker deployment tutorial for Jenkins beginners

This article deploys Jenkins+Maven+SVN+Tomcat thr...