[Solved]Redirect to another page not working

First of all I apologize, because I do not know how to speak English correctly, but I need a lot of help.
I have a problem redirecting to another page, I make an ajax query, it returns everything correctly but when I get in the command to redirect I will not try several commands and none worked, I am new to framework7, but I hope they can help me, below the code that I’m using. remembering that the version I use of framework7 is 2.1.3

// Initialize your app
var myApp = new Framework7({
animateNavBackIcon: true,
// Enable templates auto precompilation
precompileTemplates: true,
// Enabled pages rendering using Template7
swipeBackPage: false,
swipePanelOnlyClose: true,
pushState: true,
template7Pages: true

});

// Export selectors engine
var $$ = Dom7;

// Add main View
var mainView = myApp.addView(’.view-main’, {
// Enable dynamic Navbar
dynamicNavbar: false,
});
var subnaview = myApp.addView(’.view-subnav’);

$(document).ready(function() {
$("#LoginForm").submit(function(){
console.log(‘entrou’);
alert(‘entrou’);
$.ajax({
type: “POST”,
url: “http://www.site.com.br/app/webservices.php”,
data: {
acao: ‘login’,
login: $(’#usuario’).val(),
senha: $(’#senha’).val(),
},
async: false,
dataType: “json”,
success: function (json) {
if(json.result == true){
localStorage.login = json.dados.login;
localStorage.senha = json.dados.senha;
localStorage.nome = json.dados.nome;
localStorage.idMembro = json.dados.idMembro;
mainView.router.loadPage({url:‘areamembro.html’, ignoreCache:true});

                }else{
                   alert(json.msg);
                   console.log(json.msg);
                }
            },error: function(xhr,e,t){
                console.log(xhr.responseText);                
            }
        });	
	});        

})

The router.loadPage() method is changed to router.navigate() in v2

I think you should try app.router.navigate
this is my example

app.router.navigate('url?parameter1=' + value1+ '&parameter2=' + value2);
                
1 Like

I found that the redirect (mainView.router.loadPage (‘areamembro.html’):wink: is working, but for some reason after this redirect it is redirected back to the page where it was, as if it were redirected twice.
anyone have any suggestions why this happens or how to alulate this second redirect?
If you need more details just ask.

I confirmed that it is redirected to the correct page, I put an alert and it executed, but it returns or pernace in the page that I was, for example:
I’m on the contact page, when I click to open the panel to login, it executes the code I posted above and is redirected to the page I want, but I do not know how the contact page is displayed again, the ajax (code I posted above) need to close this contact page somehow, so that this new page that I want is displayed?

  1. don’t use alert, as it can break things
  2. as you develop app with v1, it is hard to say what is happening there, but there is something wrong on your side, it shouldn’t redirect back after page load. Would be good if you can provide a live link so we can take a look at it

the address is http://www.[edited].com.br/app/
the problem happens when I try to log in (first top right icon)
the email for tests [email protected] and the password abc123
must be redirected to areamembro.html
this page will be written
Área de Membros

Would anyone have any ideas to help?

You need to prevent form submit to reload your page:

$("#LoginForm").submit(function(event){
  event.preventDefault();
  // rest of your logic

Thank you very much, it was that.