我正試圖發送一個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