pass array as parameter in an axios request

偶尔善良 提交于 2019-12-11 00:30:10

问题


I need to make a request through axios, in which I want to pass as an array an array of this type [1,2,3,4]. I need this data to make a selection query from my backend, my question is: should I use a GET or POST request and what would be the correct way to pass this array?


回答1:


You can POST it as json data

let data=[1,2,3,4,5];
let json=JSON.stringify(data);
let post_data={json_data:json}
axios.post('/url',post_data)
  • use JSON.stringify to convert it to json string
  • Use POST method to send data to server
  • Use json_decode to convert json back to array on server side

On laravel side you can do like below

$jsonArray = json_decode($response,true);


来源:https://stackoverflow.com/questions/49682409/pass-array-as-parameter-in-an-axios-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!