how to redirect from ajax?

0

Very good I have a problem to redirect from use ajax post request

The problems are as follows:

I have a div which receives only all the validation texts that could occur in the application

  <div id="resultado">

  </div>

and I have my ajax application

$(function(){
          $("#btn_entrar").click(function(){
                var url = "clases/loginclass.php";
                $.ajax({
                    type:"POST",
                    url: url,
                    data: $("#frm_login").serialize(),
                    success: function(data){

                        if(data.redirect){
                           window.location.href = data.redirect;

                        }else {
                            $("#resultado").html(data);
                        }

                    }
                });

                return false;
          });
        });

at the moment of wanting to redirect from the document loginclass.php with the code

  header('Location: ../reporte.php');

nothing happens that I am doing wrong?

    
asked by Wilfredo Aleman 17.07.2017 в 22:25
source

1 answer

1

Do it with window.location or locación.href , I assume that in data.redirect you have a URL :

  $.ajax({
                        type:"POST",
                        url: url,
                        data: $("#frm_login").serialize(),
                        success: function(data){

                            if(data.redirect){
                               location.href = "http://www.miweb/destino";

                            }else {
                                $("#resultado").html(data);
                            }

                        }
                    });

Return false is not necessary.

    
answered by 17.07.2017 / 22:47
source