Answer the question
In order to leave comments, you need to log in
Why is an empty array returned when sending a variable containing table data to VueJS?
Good afternoon!
The following data is available:
data: {
newposition: []
}
<tr v-for="table in newposition.table">
<td>{{ table.linenum }}</td>
<td>{{ table.name}}</td>
...... и тп.
</tr>
axios.post( 'json.php?order=add', {table: this.newposition.table});
[table] => ,
for( var i = 0; i < this.newposition.table.length; i++ ){
let table = this.newposition.table[i];
formData.append('table[' + i + ']', table);
}
[table] =>
[0] =>
[1] =>
....
Answer the question
In order to leave comments, you need to log in
As a result, we managed to solve with a artisanal enumeration method
for( var i = 0; i < this.newposition.table.length; i++ ){
formData.append('table[' + i + '][linenum]', this.newposition.table[i]['linenum']);
formData.append('table[' + i + '][name]', this.newposition.table[i]['name']);
.....
}
Try like this
axios({
method: 'post',
{
'Content-Type': 'application/json',
'X-Requested-With': 'XMLHttpRequest'
},
url,
JSON.stringify(data),
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question