请查看下面的简单表单:
<form method="GET" action="index.php">
<input type="text" name="price_min" >Min
<input type="text" name="price_max" >Max
</form>
当我发送只填充一个字段的表单时,在我的网址中,我得到未填充密钥的空值
(例如 index.php?price_min=
)。
问题:
答案 0 :(得分:1)
您可以解析序列化字符串并删除空白值。然后你可以使用jQuery使用post到必要的api。
topLevel <- c("u", "v", "dv", "t")
midLevel <- c("e", "o", "d")
botLevel <- c("User_Timezone", "Session_nb", "Energy_Balance", "Global_Playtime")
do.call(rbind, lapply(li[[1]], function(x) {
do.call(rbind, lapply(x$l, function(y) {
if(y$e == "100_SESSION_START") {
c(y[midLevel], y$p[botLevel], x[topLevel])
}
}))
}))
e o d User_Timezone Session_nb Energy_Balance Global_Playtime
[1,] "100_SESSION_START" 24 147988 "-08:00" "0" "89" "0"
[2,] "100_SESSION_START" 169 5199 "-08:00" "0" "0" "0"
u v dv t
[1,] "BC0F6A3A2840B6F48386BABC5F34B480BA4F9929" "0.1.0" "Unidentified" 1.462924e+12
[2,] "C950FC733D883E11E36E15A705E05A3CC7748C3A" "0.1.0" "OPPO Mirror 5" 1.462909e+12
$("#btn").on("click", function() {
var formjson = $("#frmTest").serialize();
var result = formjson.split("&").filter(function(val) {
return val.split("=")[1].length > 0;
}).join("&")
console.log("Serialized String:", formjson);
console.log("Processed String:", result);
// $.get('action.php', formjson, function(response){ ... })
});
答案 1 :(得分:0)
使用jQuery发送像这样的字段
$('your_form').submit(function() {
var min_price = $("#min_price").val();
var max_price = $("#max_price").val();
var string = "";
if(min_price.length > 0){
string += "min_price="+min_price
}
if(max_price.length > 0){
string += "&max_price="+max_price
}
window.location.href = 'index.php?'+string;
});
希望它有所帮助!