Client side script seems to not work on page change
-
@frostzn no that's fine that's how I tested it as well.
-
You can add a console.log and see if it is getting triggered at all.
$(window).on('action:ajaxify.end', function(ev, data) { console.log('action:ajaxify.end'); if(ajaxify.data.template.name !== 'login' && ajaxify.data.template.name !== 'register'){ if (!app.user.uid || app.user.uid === 0) { ajaxify.go('login'); } } });
-
So it is always going into the
action:ajaxify.end
handler? Can you try the below and see if it works?$(window).on('action:ajaxify.end', function(ev, data) { console.log('action:ajaxify.end'); if(ajaxify.data.template.name !== 'login' && ajaxify.data.template.name !== 'register'){ if (!app.user.uid || app.user.uid === 0) { $('#content, #footer').removeClass('ajaxifying'); ajaxify.go('login'); } } });
-
No worries, is this a public site or are you testing on local?
-
Well I was testing locally as well and wasn't able to reproduce. For me everytime I try to navigate
console.log('action:ajaxify.end');
gets executed and it sends me back to the login page. -
You can always setup a new blank nodebb on latest version and test there to rule out anything else.
-
@baris This specific function is currently on a mostly blank slate, which makes it more confusing as well. I've tried putting in an console log after each if statement as well and it all goes through. It even goes to the
ajaxify.go('login')
but that just seems to do nothing. -
Hmm, can you try putting some more console.logs in
ajaxify.go
there are some cases where that function will not do anything. For example if there is already an ajaxify in progress it returns early.Maybe you are getting caught by the ajaxify timer which prevents quick ajaxifies. https://github.com/NodeBB/NodeBB/blob/master/public/src/ajaxify.js#L41-L43.
In that case try it on the
develop
branch. Looks like @julian fixed that on that branch https://github.com/NodeBB/NodeBB/commit/b4297cd8f065a94e7de5a3ad4b992e61c9234ca0 -
@baris I copied the the code from the 2nd link into my version of Nodebb and that fixed the issue! Seems like there must've been an already ajaxify in progress which killed
ajaxify.go('login')
Thank you so much! The issue is resolved!
-
@frostzn yeah that explains it, when you click to go to another page an ajaxify starts and when you try to call ajaxify.go('login') it is getting caught by that code because the previous one hasn't finished yet.
We will release 3.5.1 this week
-