-1

I'm trying to redirect to other view after an ajax call but it doesn't work.

The ajax call works, but when it reaches the redirection line it just doesn't work and redirect to the homepage.

This is my ajax call:

<script type="text/javascript">
    function feedback(ofertaId){            
        $.ajax({
            type : "POST",
            url : 'mensaje/mensajeFeedback.do',
            contentType: 'application/json; charset=utf-8',
            data: JSON.stringify({'ofertaId': ofertaId}),
            async: false,
            cache: false,
            success: function(callback){            
                if(localStorage.getItem("language") == "en"){
                    alert("Your mentor has been notified successfully");
                }else{
                    alert("Su tutor ha sido notificado correctamente");
                }
                window.location.href = "alumno/practicas.do";

            },
            error: function (xhr) {
                alert('Error ' + xhr.status);
            }
        });
    };
</script>

I have no idea why it's redirecting to homepagwe instead "alumno/practicas.do" since I've done the same thing in other ajax calls. Any idea?

EDIT:

Actually I want to do the redirection thing because the application redirects by itself to the homepage when the ajax call finishes. The redirection works if I just move the line outside the ajax call, so the line itself is working.

DaniR
  • 85
  • 12

2 Answers2

0

Maybe there is a server component that redirects wrongly.

You can full diagnose it as follows:

  1. Open Chrome dev tools (F12)
  2. Go to network tab
  3. Enable "preserve log"

enter image description here 4. Check the network log.

Julian
  • 33,915
  • 22
  • 119
  • 174
  • the redirect to the homepage should be there. Is it there? – Julian Jan 13 '19 at 18:48
  • No, it's not. Actually I want to do the redirection thing because the application redirects by itself to the homepage when the ajax call finishes – DaniR Jan 13 '19 at 19:03
0

Usually I use absolute path for redirection in JavaScript.

like this:

var loc = window.location.origin + "/" + window.location.pathname.split('/')[1] + "/alumno/practicas.do"
location.replace(loc)

and it always works fine.

rodahviing
  • 73
  • 1
  • 7