简体   繁体   中英

Passing array to AXIOS post

I have this array:

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

And I want to post it using axios and I cannot seem to achieve this. I am looking to end up with:

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

I have tried:

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) {

I cannot find an example of what should be common. Thanks

postData is not array, it's object and correct definitions is postData = {region_id: 18, net_forces: 29, region_adder: 1, my_game_action: "deploy", active_player_id: 1}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM