I am of the understanding after doing research that JSON is used however I am unsure of the processes. The code below is my AJAX the console log after.done is not currently working however it was working when I had success as part of the AJAX object.
AJAX
$(document).on('click', '#button', function() {
var wrap = $(this).closest('div.form_wrap');
wrap.find('form').each(function() {
var id = $(this).prop('id');
var arr = jQuery.makeArray( "#"+id );
var url = $(this).attr('action');
var type = $(this).attr('method');
var i = $('#'+id); // Or just $(this)
var data = i.serialize();
// setup on submit
i.submit(function(event) {
event.preventDefault();
var formElem = $(event.currentTarget);
console.log(data);
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
type : type,
url : url,
data : data,
dataType : 'json',
encode : true
})
.done(function(data) {
console.log(data);
});
});
i.submit();
});
});
Controller
public function store(Request $request)
{
//validate
$this->validate($request, array (
//'exercise' => 'required|unique:workout_goals,user_id,NULL,id,exercise,'.$request->exercise,
//'reps' => 'required|integer',
//'exercise' => 'required|unique:workout_goals,exercise,NULL,id,user_id,'.$request->user_id,
));
//store
$post = new workout_shared;
$post->date = $request->date;
$post->user_id = $request->user_id;
//$post->shared_id = $request->shared_id;
$post->exercise = $request->exercise;
$post->weight = Input::get( 'weight' );
$post->reps = $request->reps;
$post->sets = $request->sets;
//save
$post->save();
//session flash message
Session::flash('success','Workout shared!');
//redirect
return back();
}
Thanks