admin管理员组文章数量:1279207
I have associated array.
var arr = Array();
arr['a'] = 123;
arr['b'] = 234;
arr['c'] = 345;
arr['d'] = 456;
arr['e'] = 567;
i want to send this array with jquery ajax. This is not in my form so when i will click on submit button then it should e in my form so that i can post associate array data
<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) {
}
});
I have associated array.
var arr = Array();
arr['a'] = 123;
arr['b'] = 234;
arr['c'] = 345;
arr['d'] = 456;
arr['e'] = 567;
i want to send this array with jquery ajax. This is not in my form so when i will click on submit button then it should e in my form so that i can post associate array data
<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) {
}
});
Share
Improve this question
asked Apr 17, 2014 at 5:56
user3454835user3454835
1131 silver badge14 bronze badges
2
- merge the form data with your associated array before your send the ajax request? – MaiKaY Commented Apr 17, 2014 at 6:01
- How to merge? i am trying to merge but not gettin any success yet – user3454835 Commented Apr 17, 2014 at 6:19
2 Answers
Reset to default 10try this
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!');
}
});
So what is wrong? Can't you just add that array to Ajax request too?
data: {
formData: $('#sendProposalForm').serialize(),
assocArray: '<?php echo json_encode($arr); ?>'
}
本文标签: javascriptSend associate array with jquery ajaxStack Overflow
版权声明:本文标题:javascript - Send associate array with jquery ajax - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741249796a2365580.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论