Kal*_*exx 6 arrays ajax jquery
我正在尝试将javascript数组发送到我的Web服务器以获取ajax请求.这是我的代码:
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);
}
});
}
Run Code Online (Sandbox Code Playgroud)
阵列正在形成正确,因为当我点击$.ajax()调用时Chrome的开发人员工具将标签对象显示为具有2个元素的数组(所有元素都只是字符串).
但是,根据fiddler的说法,发送到服务器的实际帖子参数是:
undefined=undefined
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
编辑 Console.Log显示:
console.log(tags)
["portability", "testing"]
undefined
Run Code Online (Sandbox Code Playgroud)