我正在尝试将
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);
}
});
}
数组正在正确形成,就像当我点击$.ajax()调用时,Chrome的开发人员工具将标记对象显示为具有2个元素的数组(所有元素都只是字符串).
但是,根据fiddler的说法,发送到服务器的实际帖子参数是:
undefined=undefined
我究竟做错了什么?
编辑
Console.Log显示:
console.log(tags) ["portability","testing"] undefined
解决方法
console.log(标签)对标签的评价是什么?
尝试像这样发送:
data : ({tags : tags})