duanhao5038 2016-06-10 18: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-10 18:44
    关注

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

    customizedExercises = JSON.stringify(this.customizedExercises);

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

报告相同问题?

悬赏问题

  • ¥15 C#i编程中so-ir-192编码的字符集转码UTF8问题
  • ¥15 51嵌入式入门按键小项目
  • ¥30 海外项目,如何降低Google Map接口费用?
  • ¥15 fluentmeshing
  • ¥15 手机/平板的浏览器里如何实现类似荧光笔的效果
  • ¥15 盘古气象大模型调用(python)
  • ¥15 传人记程序做的plc 485从机程序该如何写
  • ¥15 已知手指抓握过程中掌指关节、手指各关节和指尖每一帧的坐标,用贝塞尔曲线可以拟合手指抓握的运动轨迹吗?
  • ¥50 libwebsockets 如何添加其他socket事件回调
  • ¥50 实现画布拖拽算子排布,通过flink实现算子编排计算,请提供思路
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部