Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
139
rated 0 times [  142] [ 3]  / answers: 1 / hits: 19126  / 6 Years ago, thu, april 5, 2018, 12:00:00

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?


More From » ajax

 Answers
16

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

[#54751] Tuesday, April 3, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kevonmoisesf

Total Points: 693
Total Questions: 101
Total Answers: 128

Location: Reunion
Member since Mon, Dec 28, 2020
3 Years ago
kevonmoisesf questions
Sat, Jan 23, 21, 00:00, 3 Years ago
Tue, Feb 18, 20, 00:00, 4 Years ago
Wed, Jun 12, 19, 00:00, 5 Years ago
;