javascript - Ajax post req of array item gives me a null response -
as title says, can send post request non array item using vue resource no problem.
when comes sending array data response null array.why 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; });
you need pass array of objects json before sending on php.
customizedexercises = json.stringify(this.customizedexercises);
Comments
Post a Comment