I have a function that keeps grades:
<script>
function guardarNotas(){
var object = [];
$(".nota").each(function (index, element){
object.push({
'idMatricula': $(element).data('idMatricula'),
'idEvaluacion': $(element).data('idEvaluacion'),
'nota': $(element).val()
});
});
$.ajax('../savecalificacionesasignatura', {
contentType: 'aplication/json',
data: JSON.stringify(object),
method: 'post',
headers: {
'X-CSRF-TOKEN' : $('[name="_token"]').val()
},
success: function (data) {
console.log('se ha guardado');
},
error: function (data) {
console.log('Error:', data)
}
});
}
This is my controller:
public function guardarNotas(Request $request)
{
$notas = $request->input();
foreach ($notas as $nota){
$nota = Nota::updateOrCreate([
'id_matricula' => $nota['idMatricula'],
'id_evaluacion' => $nota['idEvaluacion']
], ['nota' => $nota['nota']]);
}
//responder true or false ? segun se guarda o devolver error
return response()->json(array('success' => true));
}
I want that when I press the save button I redirect to another view, I've already tried the success with:
window.location='thank-you.html'
window.location.href='thank-you.html'
location.href="page.html"
but I do not achieve redirection. Also probe in the controller with, return redirect :: to (""), return view (""), return url (""). Someone knows how to correctly redirect