S
S
Silverviql2018-04-22 22:44:11
Yii
Silverviql, 2018-04-22 22:44:11

How to restrict pjar to update icon?

I want to dynamically update notification icon in yii2. But the problem is that he starts creating a div and throwing data from the table model into it. It also updates the icon, but you can click on it only until the script updates it, after the icon becomes unclickable, so you can click on it, you need to refresh the page and open it before the script runs out.
In the view I registered pjax.

<?php Pjax::begin(['id' => 'pjax-container']); ?> 
echo $notifications == null ? '<div class="notification-icon">' : '<div class="notification-icon newNotification">'; 
<?php Pjax::end(); ?>

In script.js, I registered a call every 3 seconds.
$(document).ready(function(){
    setInterval(function(){
        $.pjax.reload('#pjax-container')
    }, 3000);

This is what I get as output.
5adce6025ec7d643707266.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Fedorov, 2018-04-23
@qonand

It also updates the icon, but you can click on it only while the script does not update it

You can't click on it because Pjax, when updating, replaces the html on the page with the one returned by the server. Accordingly, the scripts attached to your html-element flies, and after each Pjax update they should be outweighed
A rather crooked solution that only creates unnecessary loads on the server and on the client. For such tasks, it is better to use sockets.

M
Maxim Timofeev, 2018-04-23
@webinar

How do you catch a click on an icon?
In theory, this is how it should catch:

$('body').on('click', '.someIconClass', function(){
concole.log('уряяя!!!');
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question