jquery - 在jquery中使用ajax发布一个空数组

标签 jquery ajax arrays

我试图使用 ajax 调用发布一个空数组,但数据被发布为一个空字符串,即 Parts: 。我希望将数据作为 Parts:[] 发布,但这不会发生,因为 Web 服务仅处理空集合,即 Parts[]。

Code:
var parts=[];
$.ajax({
type: "POST",
url: "http://api-test.example.com",
dataType: "json",
headers:{Authorization:authHeader},
data: "Parts="+parts,
    success: function (result) {
    },
error: function (result){
}
});

知道如何解决这个问题吗?

最佳答案

尝试将数据作为数据传递:{}

$.ajax({
type: "POST",
url: "http://api-test.example.com",
dataType: "json",
headers:{Authorization:authHeader},
data: {Parts : parts} ,
    success: function (result) {
    },
error: function (result){
}
});

关于jquery - 在jquery中使用ajax发布一个空数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23334331/

相关文章:

python - 如何为 Tensorflow 占位符提供 numpy 数组?

jquery - 将 div 限制为仅适用于其父级

jquery 背景填充 100% 屏幕,但切断了图像的一部分

jQuery load() 和 Facebook 评论

javascript - 在所有元素上应用 jquery 代码

c# - 按字符串数组拆分字符串,并在 C# 中包含用于拆分最终数组的单词

javascript - "jQuery.event.special"API(用于自定义事件)的文档在哪里?

javascript - 如何在更新集合时更新模板的一部分?

javascript - 在 Google Ajax 中显示页面加载微调器

c# - 如何将 List<Tuple<string, int>> 转换为 string[]?