I have an Array, i want to get all values one by one from Array and post value using axios to rest-api django
In Django i have model:
class Cars(models.Model):
car = models.CharField(max_length=100)
i want to add data in my model from axios post here is my array, from this array i want to get value and add in to my model one by one on single submit,
let cars = [
["Saab", "Volvo", "BMW"],
["Toyota", "Alto", "Civic",]
]
i have try like this,
handleFormSubmit = event => {
event.preventDefault();
for (var i = 0; i < cars.length; i++) {
axios.post('myURL',{
car: car[i]
})
.then(res => console.log(res))
.catch(err => console.log(err));
}
}
and after on submit i got Error: "Request failed with status code 400", when i make axios post outside the loop it is fine, but i want to add multiple data from an array.