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
Add a ment  | 

2 Answers 2

Reset to default 10

try 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