的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