2010-08-13 42 views
6

我正试图发送一个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 
+4

'tags'是不是关联数组,所以我想象jQuery是一个困难时期,从它建立一个查询字符串。虽然我很惊讶,但它将其视为“未定义”,这可能是问题所在。 – 2010-08-13 15:57:25

回答

9

什么是一个的console.log(标签)说的标签?

尝试发送这样的:

data : ({tags : tags}) 
+0

添加console.log输出到问题 – KallDrexx 2010-08-13 16:13:15

+0

这工作! (在尝试解决方案之前,我忘记刷新我的页面) – KallDrexx 2010-08-13 16:15:25

相关问题