I making chat and load new message by using setInterval.
setInterval(function () {
// ajax message data reload
}, 2000);
but when I leave the page the setInterval still working how can I stop it ?
I making chat and load new message by using setInterval.
setInterval(function () {
// ajax message data reload
}, 2000);
but when I leave the page the setInterval still working how can I stop it ?
Use pagebeforeremove event
Can you show me how to use it?
You need to use clearInterval
JS method:
var interval = setInterval(..., 1000);
// and to remove it
clearInterval(interval)
You need to clear it in page:beforeout
page event
$$(document).on('page:init', '.page[data-name="message"]', function (e, page) {
var chatInterval = setInterval(function () {
// ajax message data reload
}, 2000);
});
$$(document).on('page:beforeout', function (e) {
clearInterval(chatInterval);
});
It’s not stop
В консоле будет ошибка. Переменная локальная и недоступна извне.
var chatInterval;
$$(document).on('page:init', '.page[data-name="message"]', function (e, page) {
chatInterval = setInterval(function () {
// ajax message data reload
}, 2000);
});
$$(document).on('page:beforeout', function (e) {
clearInterval(chatInterval);
});
Thank you so much >.<