Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing an array back to the server using JQuery .post()

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?

like image 675
FloatLeft Avatar asked Jul 17 '26 12:07

FloatLeft


1 Answers

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);
    }
});
like image 114
Darin Dimitrov Avatar answered Jul 19 '26 06:07

Darin Dimitrov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!