gpt4 book ai didi

javascript - 数组项的 Ajax post req 给我一个空响应

转载 作者:行者123 更新时间:2023-12-03 06:45:28 25 4
gpt4 key购买 nike

正如标题所示,我可以使用 Vue Resource 发送对非数组项的 post 请求,没有任何问题。

当发送数组数据时,响应是空数组。为什么会发生这种情况?

submit:function(){
var customizedExercises = this.customizedExercises;
this.$http.post('/api/customized-exercises', customizedExercises).then(function(response){
console.log(response);
}, function(response){
return response;
})
},


addSelectbox: function(){
this.customizedExercises.push({ weight:'',sets_duration:'',name:'',reps:'',exercise_day_id:'' })
}
},

数据

customizedExercises : [
{ weight:'',sets_duration:'',name:'',reps:'',exercise_day_id:'' }
],

html

<button type="submit" @click="addSelectbox">add select box</button>
<div v-for=" customizedExercise in customizedExercises" class="input-group">

<span class="input-group-addon">
<select class="selectpicker form-control" v-model="customizedExercise.name" name="name" id="name">
<option value="{{ exercise.name }}" v-for="exercise in exercises">{{ exercise.name }}</option>
</select>
</span>

<span class="input-group-addon">
<select class="selectpicker form-control" v-model="customizedExercise.sets_duration" name="sets_duration" id ="sets_duration">
<option v-for="number in numbers" value="{{number}}">{{number}}</option>
</select>
</span>

<span class="input-group-addon">
<select class="selectpicker form-control" v-model="customizedExercise.weight" name="weight" id="weight">
<option v-for="number in numbers" value="{{number}}">{{number}}</option>
</select>

{{数字}}

<input type="hidden" name="exercise_day_id" v-model="customizedExercise.exercise_day_id" id="exercise_day_id" value="1" />

路线

Route::post('/api/customized-exercises',function() {
$inputs = Request::json()->all();

return $inputs;


});

最佳答案

您需要将对象数组传递到 JSON,然后再将其发送到 PHP。

customizedExercises = JSON.stringify(this.customizedExercises);

关于javascript - 数组项的 Ajax post req 给我一个空响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37759278/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com