I am working on a project with vuejs and to handle my AJAX requests I use Axios, the problem is I can not send array inside my formData, I see [object] on my request in network tab of developers panel. Is it possible to pass as a parameter to a POST request with an array of objects inside main object, of this type: inside my object I have an array with lenght 2 as below
(3) [{…}, {…}, {…}, __ob__: Observer]
0:
created_at: "2018-12-16 18:37:00"
id: 1
properties: Array(8)
0: {…}
1: {…}
2: {…}
3: {…}
4: {…}
5: {…}
6: {…}
7: {…}
title: "Building properties"
updated_at: "2018-12-16 18:37:00"
__proto__: Object
1: {…}
2: {…}
I tried JSON.stringy both for array and whole object but I get 405 method not allowed. I also tried adding config. I see some solution as paramsSerializer but can not understand where I should write it exactly.
var data = {
user_id: this.user_info,
type_id: this.dorm_type,
city_id: this.city,
district_id: this.district,
is_active: this.is_active,
name: this.name,
slug: this.slug,
keywords: this.keywords,
description: this.description,
member: this.member,
capacity: this.capacity,
is_wifi: this.is_wifi,
meal: this.meal,
properties: this.properties
const formData = new FormData();
Object.keys(data).map(e => {
formData.append(e, data[e]);
});
for (let i = 0; i < this.images.length; i++) {
formData.append("images[]", this.images[i]);
}
for (let i = 0; i < this.props.length; i++) {
formData.append("props[]", this.props[i]);
}
for (let i = 0; i < this.university.length; i++) {
formData.append("university[]", this.university[i]);
}
formData.append("_method", "PUT");
if (this.logo) {
formData.append("logo", this.logo);
}
if (this.cover) {
formData.append("cover", this.cover);
}
console.log(formData);
this.$Progress.start();
//this.axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
this.axios.post("dorms/" + this.id, formData).then(response => {
console.log(response.data);
if (response.status == 200) {
this.$Progress.finish();
}
});
},
in headers section inside formData, I see properties as objects
member: null
capacity: 28
is_wifi: 0
meal: 0
properties: [object Object],[object Object],[object Object]
content: <p>null</p>
content_en: <p>Under Construction</p>
dataobject syntax is not correct. There is a dangling closing}.