gpt4 book ai didi

javascript - 使用 jquery ajax 发送关联数组

转载 作者:行者123 更新时间:2023-11-30 07:24:17 25 4
gpt4 key购买 nike

我有关联数组。

var arr =   Array();
arr['a'] = 123;
arr['b'] = 234;
arr['c'] = 345;
arr['d'] = 456;
arr['e'] = 567;

我想用 jquery ajax 发送这个数组。这不在我的表单中,所以当我单击提交按钮时,它应该出现在我的表单中,以便我可以发布关联数组数据

<form id="sendProposalForm" action="<?php echo frontpath(FILENAME_AJAXFILE);?>" method="post">

<input type="hidden" name="action" value="sendRequestProcess" />
<input type="hidden" name="durationHidden" id="durationHidden" value="0" />
<input type="hidden" name="priceSenstivityHidden" id="priceSenstivityHidden" value="0"/>
<input type="hidden" name="responseRateHidden" id="responseRateHidden" value="10" />
<input type="hidden" name="addTagsHidden" id="addTagsHidden" value="" />
<input type="hidden" name="addAttachmentHidden" id="addAttachmentHidden" value="" />
<input type="text" name="attachmentOrignalNameHidden" id="attachmentOrignalNameHidden" value="" />

$.ajax({url    :    "<?php echo frontpath(FILENAME_AJAXFILE);?>",
type : "post",
data : $('#sendProposalForm').serialize(),
success:function(res) {

}
});

最佳答案

试试这个

var arr = Array();
arr['a'] = 123;
arr['b'] = 234;
arr['c'] = 345;
arr['d'] = 456;
arr['e'] = 567;

var obj = $.extend({}, arr); /* convert your array to an object */

$.ajax({url: "<?php echo frontpath(FILENAME_AJAXFILE);?>",
type: "post",
data: $('#sendProposalForm').serializeArray() + '&' + $.param(obj), /* merge your form with the new obj (your array) */
success: function (res) {
alert('SUCCESS!');
}
});

关于javascript - 使用 jquery ajax 发送关联数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23125627/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com