将数组传递给AXIOS帖子

时间:2017-09-02 10:30:53

标签: javascript jquery axios

我有这个数组:

postData = [region_id: 18, net_forces: 29, region_adder: 1, my_game_action: "deploy", active_player_id: 1]

我想用axios发布它,我似乎无法实现这一目标。我希望最终得到:

axios.post(turn_route, {
  region_id: 18,
  net_forces: 29,
  region_adder: 1,
  my_game_action: 'deploy',
  active_player_id: 1
})

我试过了:

axios.post(turn_route, JSON.stringify(postData))
.then(function(response) {

axios.post(turn_route, postData)
.then(function(response) {

axios.post(turn_route, data: {postData: postData})
.then(function(response) {

axios.post(turn_route, {params: {postData}})
.then(function(response) {

我找不到一个应该是什么常见的例子。感谢

1 个答案:

答案 0 :(得分:-2)

postData不是数组,它的对象和正确的定义是     postData = {region_id: 18, net_forces: 29, region_adder: 1, my_game_action: "deploy", active_player_id: 1}

你需要    axios.post(turn_route, postData).then(function(response) {})