的jQuery添加/推()值將Ajax POST jQuery中序列化()或serializeArray()
$('#speichern').live('click' , function() {
// [a] var data_save = $('#form_rechn').serializeArray();
var data_save_ser = $('#form_rechn').serialize(); //[b]
// [a] data_save[data_save.length] = {"name":"action","value":"save" },{"name":"total","value": Number($('#grandTotal').text().replace(/EUR/g, ""))};
var addintional = 'action=save&mysql=update' + '&' + 'total=' + Number($('#grandTotal').text().replace(/EUR/g, ""));//[b]
var data_save = data_save_ser + '&' + addintional;//[b]
$.ajax({
type : "POST",
cache : false,
url : 'invoice_new_action.php',
data : data_save,
error:function (xhr, ajaxOptions, thrownError){
alert(xhr.status);
alert(thrownError);
},
success : function(data) {
$.fancybox(data);
}
});
});
的並[b] -part工作得非常好;然而,爲什麼不起作用[a]部分?這不是被推: ,{"name":"total","value": [..]
PHP輸出繼電器經由的print_r($ _POST)
並[b] -version
Array ([pnr_item_1] => 1 [pkt_item_1] => HostingXXL [desc_item_1] => 20GB, 1x.de [qty_item_1] => 4 [price_item_1] => 15.5 .... [action] => save [mysql] => update [total] => 62)
並[a] -version
Array ([pnr_item_1] => 1 [pkt_item_1] => HostingXXL [desc_item_1] => 20GB, 1x.de [qty_item_1] => 4 [price_item_1] => 15.5 .... [action] => save)
希望我的問題/問題很清楚。 什麼是最好的方法? 有更好的方法來這麼ID?
是否有可能合併$('#form1')。serializeArray()和$('#form2')。serializeArray()並通過ajax發送它? – hoerf 2010-12-15 13:57:27
@hoerf - 哦是的,這樣做:var arr = $('#form1')。serializeArray(); $ .merge(arr,$('#form2')。serializeArray());',那麼'arr'將包含兩個內容,只是將它用於'data'參數。 – 2010-12-15 14:01:38