Redirection in ajax does not work

0

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

    
asked by Edgardo Escobar 19.06.2017 в 05:53
source

1 answer

1

For the address try this:

    window.location = "@Url.Action("EditarFactura", "Facturas")";

if you put it in a method would be something like this:

function Edit(Id)
{
   localStorage.setItem("FacId", JSON.stringify(Id));
   window.location = "@Url.Action("EditarFactura", "Facturas")";
}
    
answered by 13.09.2018 в 00:58