基本上我有一个部分有6个像这样的选择框我正在使用ajax动态填充它们,但是填充的选择字段的数量根据servlet响应而变化,例如显示的某个时间2选择框或有时5、4、3等...我正在隐藏其他未填充的选择框。现在我想在按钮单击事件上选择时将值输入到相应的输入隐藏字段中,并且我只想将显示的选择框值传递给servelt而不是全部
<div id="section-2" class="section-content">
<fieldset id="field-1">
<label for="field-1">Data 1</label>
<select id="factor-1"></select>
</fieldset>
<fieldset id="field-2">
<label for="field-2">Data 2</label>
<select id="factor-2"></select>
</fieldset>
<fieldset id="field-3">
<label for="field-3">Data 2</label>
<select id="factor-3"></select>
</fieldset>
<fieldset id="field-4">
<label for="field-4">Data 4</label>
<select id="factor-4"></select>
</fieldset>
<fieldset id="field-5">
<label for="field-5">Data 5</label>
<select id="factor-5"></select>
</fieldset>
<fieldset id="field-6">
<label for="field-6">Data 6</label>
<select id="factor-6"></select>
</fieldset>
<button type="button" id="section2-next"> Next </button>
<input type="text" id="data-1-Id"/>
<input type="text" id="data-2-Id"/>
<input type="text" id="data-3-Id"/>
<input type="text" id="data-4-Id"/>
<input type="text" id="data-5-Id"/>
<input type="text" id="data-6-Id"/>
</div>
这是我的$.ajax()
电话..
$("#section2-next").click(function(){
var param1= $("#data-1-Id").val();
var param2= $("#data-2-Id").val();
var param3= $("#data-3-Id").val();
var param4= $("#data-4-Id").val();
var param5= $("#data-5-Id").val();
var param6= $("#data-6-Id").val();
// here i am having problem how to pass only filled input filed value not all 6 parammeters on every ajax request.........
var dataString = 'param1='+param1+"¶m2="+param2+"¶m3="+param3+"¶m4="+param4+"¶m5="+param5+"¶m6="+param6;
console.log(dataString);
$.ajax({
type:"Post",
url:"GetPrice",
datatype:"json",
data : dataString,
success: function(data){
// var price = data.asset;
var parsed = JSON.parse(data);
var price = parsed[0].FormattedPrice;
$('#price').empty().text(price);
}
});
});
以及如何检查 servlet 中是否存在该参数?