3

There are loads of questions and answers regarding the issue of posting arrays back to the server using jquery.

However I cant seem to find any solutiion to the problem I'm having. Basically the code below should return an array of ID's back to the server:

I know the array contains items as the length of the array always matches the number of selects that have the option "true" selected

var option = $(".option-select").filter(function () { return $(this).val() == "true"; }).map(function () { return this.id; }).get();
alert(option.length);
$.post("/Quote/GetOptionPrice", { myParam: option }, function (response) { $(".price").html(response); });

This is what is passed to the server:

"myParam[]"

Where am I going wrong?

FloatLeft
  • 1,317
  • 3
  • 23
  • 40
  • are you remembering to serialize the array before posting it? http://api.jquery.com/jQuery.param/ <-- that one's the correct url – pxl Oct 15 '10 at 10:27

1 Answers1

1
var option = $('.option-select').filter(function () { 
    return $(this).val() == "true"; 
}).map(function () { 
    return this.id; 
}).toArray();

$.ajax({
    url: '/Quote/GetOptionPrice',
    type: 'POST',
    data: { myParam: option },
    traditional: true,
    success: function(response) {
        $('.price').html(response);
    }
});
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928