I have a ListBox on my page, and I\'d like to make an AJAX post containing all the selected items. Here\'s my code:
$(\'#btnSubmit\').click(function() {
Is the select element inside a form tag? You can serialize the entire form and send it through easily.
var formdata = $('#formId').serialize();
Then in your ajax call
data: formdata,
--
Recently I dealt with a very similar issue. I am also using a C# Web Service, but the data I am dealing with is completely dynamic. I had to find a way to collect a variable length array and pass it as a single JSON string (along with some other fixed variables). I used the JSON2 library from http://json.org and collected the data by putting a certain class on all desired input fields, and using the title attribute as a key.
var formdata = {};
$(".formInputField").each(function() {
formdata[$(this).attr('title')] = $(this).val();
});
var mydata = JSON.stringify({ 'formdata': JSON.stringify(formdata), 'othervar' : otherVal1, 'othervar2' : otherVal2, 'othervar3' : otherVal3 });
Then I passed mydata
as above.