duanhao5038 2016-06-11 02:10
浏览 26
已采纳

Ajax post req of array item给出了一个null响应

As the title says, I can send a post request for a non array item using Vue Resource with no problem.

When it comes to sending an array data the response is a null array.Why is this happening?

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:'' })
        }
    },

data

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> 

{{number}}

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

route

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

return $inputs;


});
  • 写回答

1条回答 默认 最新

  • douhan9467 2016-06-11 02:44
    关注

    You need to pass the array of objects into a JSON before sending it over to PHP.

    customizedExercises = JSON.stringify(this.customizedExercises);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?