How do I redirect a .aspx window with an ajax call?

3

How do I redirect my current window to a new one through an ajax call?

Ajax call code:

function autenticarme() {
    var nick = $(".txtNick").val(); 
    var pass = $(".txtPass").val();
    $.ajax({
        type: "POST",
        url: "login.aspx/conectarBD",
        dataType: "text",
        async: false,
        data: "{ nick: '" + nick + "',password: '" + pass + "' }",
        contentType: "application/json; charset=utf-8",
        success: function (data) {
            window.location = data."http://localhost:52403/WebSite2/CRUD.aspx";
        }, error: function (xhr, status, error) {
            alert("Error");
        }
    });
}

Now use the following methods within succes:

   location.replace("CRUD.aspx");
   window.location.href = 'CRUD.aspx';
    window.location.assign("CRUD.aspx");
    window.open('@Url.Action("CRUD", "ReportExecution")');

None of them takes any action on me, just that the page I'm on does not move.

  

Update

With this line of code in succes, you redirect me:

window.open('CRUD.aspx')

But I opened the window in a new tab, I would like to know how I close the current window if a new one opens.

    
asked by David 27.03.2017 в 20:42
source

1 answer

1

The error is in the success of the Ajax call, the redirect is made asi .

function autenticarme() {
    var nick = $(".txtNick").val(); 
    var pass = $(".txtPass").val();
    $.ajax({
        type: "POST",
        url: "login.aspx/conectarBD",
        dataType: "text",
        async: false,
        data: "{ nick: '" + nick + "',password: '" + pass + "' }",
        contentType: "application/json; charset=utf-8",
        success: function (data) {
            location.href = "http://localhost:52403/WebSite2/CRUD.aspx";
        }, error: function (xhr, status, error) {
            alert("Error");
        }
    });
}

Example: link

    
answered by 17.04.2017 в 16:27