Answer the question
In order to leave comments, you need to log in
Ajax, Jquery and Laravel 5?
Goodnight! I'm learning laravel and I can't figure out what's the matter at all, the problem is that the controller method does not return anything, although I send the form to it.
{!! Form::open(['url'=>'#','files'=>true, 'method' => 'POST', 'id' => 'sendTest' ]) !!}
{!! Form::text('name',null,['id'=>'name']) !!}
{!! Form::text('age',null,['id'=>'age']) !!}
{!! Form::submit('Click Me!',['id'=>'ok', ]) !!}
{!! Form::close() !!}
<script>
$(document).ready(function(){
$.ajaxSetup({
headers: {
'X-XSRF-TOKEN': $('meta[name="_token"]').attr('content')
}
});
$("#ok").on("click",(function(){
var formData = new FormData(document.getElementById("sendTest"));
$.ajax({
url: 'create/',
type: 'POST',
data: formData,
dataType: 'JSON',
success: function (data) {
console.log(data);
}
});
}));
});
</script>
public function getRamos(Request $request)
{
$data = $request->all();
//return $input;
if($request->ajax()){
return response()->json([ $data
]);
}
}
Route::get('articles/create','[email protected]');
Route::post('articles/create','[email protected]');
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question