Passing an array to a server using jQuery.post ()

With questions about sending arrays to the server using jquery, there are many questions and answers.

However, I cannot find a solution to the problem that I am experiencing. Basically, the code below should return an array of identifiers to the server:

I know that the array contains elements, since the length of the array always matches the number of options selected, selected by the "true" option

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?

+3
source share
1 answer
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);
    }
});
+1
source

Source: https://habr.com/ru/post/1769706/


All Articles