[英]Jquery ajax posting only some data at a time
我一直將查詢Ajax請求用於簡單的事情,例如preventdefault表單提交,並在將表單提交到我的nodejs后端后添加beforesend函數或complete函數:
$.ajax({
type: "POST",
url: "/contact",
beforeSend:function(){
$(".loading_msg").hide();
},
complete:function(){
$(".loading_msg").show();
setTimeout(function(){
console.log('Here')
$(".loading_msg").fadeOut("slow");
$("#message").val("")
},3000)
}
});
現在,我需要只提交部分表單輸入元素。 表單內部還有動態生成的輸入元素。
有沒有辦法讓我只發送帶有我想要的ID或類的輸入框,而不發送整個表格?
如果要將某些特定數據發送到服務器,則可以像下面這樣自行配置data
:
$.ajax({
type: "POST",
url: "/contact",
data: {
myKey1: $("#myKey1").val(),
myKey2: $("#myKey2").val()
},
beforeSend:function(){
$(".loading_msg").hide();
},
complete:function(){
$(".loading_msg").show();
setTimeout(function(){
console.log('Here')
$(".loading_msg").fadeOut("slow");
$("#message").val("")
},3000)
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.