0
朋友如何將其他隱藏變量傳遞給jQuery/Ajax Post dataObj?
我有以下的jQuery的AJAX調用後
function submitForm() {
var selectedPricingTierId = "";
var lstIds = new Array();
jQuery('input[type=checkbox]').each(function() {
if(this.checked && this.id !="select_all"){
if(selectedPricingTierId == "") {
selectedPricingTierId = this.id;
} else {
selectedPricingTierId = selectedPricingTierId + "," + this.id;
}
}
});
var dataObj = {
"lstIds" : selectedPricingTierId
};
jQuery.ajax({
url : getCurrentLocation() + "/saveIncentives.action",
type : "POST",
data : dataObj,
success : function(data) {
closeWindow();
}
});
}
現在我有以下隱變量傳遞給我的dataObj
<s:hidden name="month" id="month" value="%{month}" />
<s:hidden name="year" id="year" value="%{year}" />
我如何追加以上無能在Post調用中隱藏了我的DataObj變量。
請建議您可以做一個合適的方式
感謝 所以我dataObj看起來像 VAR dataObj = { 「lstIds」:selectedPricingTierId, \t \t \t \t \t dataObj.month = $( '輸入[名稱= 「月」]')VAL()。 ; \t \t \t \t \t dataObj.year = $('input [name =「year」]')。val(); }; ?? 請讓我知道 – 2014-12-27 18:27:08
不,如果你想這樣,它應該看起來像這樣:dataObj = {「lstIds」:selectedPricingTierId,「month」:$('input [name =「month」]')。val ),「year」:$('input [name =「year」]')。val()}; – bwitkowicz 2014-12-27 18:36:43
我已經更新了一個答案,以便您可以更好地使用代碼突出顯示。如果這有助於請接受/投票答案:) – bwitkowicz 2014-12-27 18:41:00