Why does jquery send "undefined = undefined" as message parameters instead of sending array data?

I am trying to send a javascript array to my web server for ajax request. Here is my code:

function SearchTasksByTags() { // Get the list of tags currently chosen var tags = []; $('.tagit-choice input').each(function () { tags.push($(this).val()); }); // If we have no tags, don't bother searching and just clear the current results if (tags.length == 0) { $('#tagSearchResults').empty(); return; } // Retrieve the search results from the server $.ajax({ url: '<%= Url.Action("SearchByTags") %>', data: tags, type: 'POST', success: function (html) { $("#tagSearchResults").empty().append(html); } }); } 

The matrix is โ€‹โ€‹formed correctly, because when I click on the call to $.ajax() , the Chrome developer tools show the tag object as an array with 2 elements (all elements are just strings).

However, according to the violinist, the actual message parameters sent to the server are as follows:

 undefined=undefined 

What am I doing wrong?

Modify Console.Log shows:

 console.log(tags) ["portability", "testing"] undefined 
+6
jquery arrays ajax
source share
1 answer

What does console.log (tags) say about tags?

Try sending it as follows:

 data : ({tags : tags}) 
+9
source share

All Articles