【问题标题】:Ionic V1 $http post json data paramsIonic V1 $http 发布 json 数据参数
【发布时间】:2017-12-11 06:27:33
【问题描述】:

我有 2 个由 sqlite 执行生成的对象:

var info_update = {
id: 270,
cancelados: 2,
concluidos: 2,
total: 914
}

var participantes = [
    {id: "10",
     nome: "Antonio",
     idade: "4",
     ativo: 1,
     msg: "Backorder"
     },
    {id: "11",
     nome: "Carlos",
     idade: "1",
     ativo: 1,
     msg: "Flagged"
    }
]

为了发送对象,我在服务上使用此方法:

var headers = {
            'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
        };
    return $http({
        method: "POST",
        url: "remote_url.com/action",
        data: {info_update: info_update, participantes: participantes},
        headers : headers
    })

有什么问题?

The parameter info_update it's sent to server, but the parameter participantes it's send empty, as appears in the attached image

我需要发送所有数据以供服务。 我是怎么做到的?

【问题讨论】:

  • 尝试将内容类型更改为 application/json 但图像中的参与者看起来像一个空对象。也许从服务器端,你期待一个数组还是一个对象?
  • @Vivz,我更改为 application/json,但它仍然是空的:(...还有什么建议吗?
  • 你的后端期望参与者是一个数组还是一个对象?
  • 我的问题不在后端,而是在前端。我无法将对象“参与者”作为请求中的参数发送。
  • 您可以删除 Content-Type 标头并尝试一下吗?或使用“应用程序/json”

标签: javascript angularjs ionic-framework


【解决方案1】:

您的participantes 不是对象,它的数组尝试使用.map 函数将其更改为对象

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-25
    • 2011-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多