南通颐猩文化传播有限公司

當(dāng)前位置:首頁 >  站長 >  編程技術(shù) >  正文

html post請求之a(chǎn)標(biāo)簽的兩種用法解析

 2020-12-25 16:07  來源: 腳本之家   我來投稿 撤稿糾錯

  域名預(yù)訂/競價(jià),好“米”不錯過

這篇文章主要介紹了html post請求之a(chǎn)標(biāo)簽的兩種用法,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧

html post請求之a(chǎn)標(biāo)簽的兩種用法舉例,具體內(nèi)容如下:

1、使用ajax來發(fā)起POST請求

HTML代碼如下:

<a class="a_post">發(fā)起POST請求</a>

JQuery代碼如下:

$(".a_post").on("click",function(event){
event.preventDefault();//使a自帶的方法失效,即無法調(diào)整到href中的URL(https://www.cnblogs.com/)
$.ajax({
type: "POST",
url: "url地址",
contentType:"application/json",
data: JSON.stringify({param1:param1,param2:param2}),//參數(shù)列表
dataType:"json",
success: function(result){
//請求正確之后的操作
},
error: function(result){
//請求失敗之后的操作
}
});
});

2、使用form表單來發(fā)起POST請求

<form id="_form" method="post" action="target">
<input type="hidden" name="name" value="value" />
<a onclick="document.getElementById('_form').submit();">點(diǎn)擊提交</a>
</form>

總結(jié)

到此這篇關(guān)于html post請求之a(chǎn)標(biāo)簽的兩種用法解析的文章就介紹到這了,更多相關(guān)html post請求 a標(biāo)簽內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持腳本之家!

來源:腳本之家

鏈接:https://www.jb51.net/web/724755.html

申請創(chuàng)業(yè)報(bào)道,分享創(chuàng)業(yè)好點(diǎn)子。點(diǎn)擊此處,共同探討創(chuàng)業(yè)新機(jī)遇!

相關(guān)標(biāo)簽
html

相關(guān)文章

熱門排行

信息推薦