为什么jquery发送“undefined = undefined”作为我的发布参数而不是发送数组数据?
问题描述:
我正试图发送一个JavaScript数组到我的web服务器的ajax请求。这里是我的代码:为什么jquery发送“undefined = undefined”作为我的发布参数而不是发送数组数据?
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个元素(所有元素都是只是字符串)数组。
然而,根据小提琴手,实际后得到的参数发送到服务器是:
undefined=undefined
我在做什么错?
编辑 CONSOLE.LOG显示:
console.log(tags)
["portability", "testing"]
undefined
'tags'是不是关联数组,所以我想象jQuery是一个困难时期,从它建立一个查询字符串。虽然我很惊讶,但它将其视为“未定义”,这可能是问题所在。 – 2010-08-13 15:57:25