JQuery update page content while multiple users view it at the same time

时间:2016-12-02 04:50:26

标签: jquery ajax synchronization

I want to update the content changes for all users in the page.

I have this jquery code

When a user click the "assign button" it makes table tr fadeout!.

$('#check').find('input:checkbox:checked').closest('tr').fadeOut(1000);

All I want is to make it fadeout for all users at the same time

in other word I want to run the above code for all users

How can I do that ?

 $(document).on('click','#assign',function(e){
        e.preventDefault();

        var dataString = $('#employee_form').serialize();

        $.ajax({
          url: '../inc/ajax/ajax_process/supervisor_unassgined_process.php',
            type: 'POST',
            data:     dataString ,
            beforeSend: function() {
                $('#check').find('input:checkbox:checked').closest('tr').css({'backgroundColor':'#fb6c6c'});
            },
            success: function (data1) {


                $().toastmessage('showToast', {
                    text     : data1,
                    stayTime:         2000,
                    sticky   : false,
                    position : 'top-center',
                    type     : 'success',
                    closeText:         '',
                    close:            null
                });

                if(data1 == 'data has been Assigned'){


                    $('#check').find('input:checkbox:checked').closest('tr').fadeOut(1000);


                } else {
                    parent.css({'backgroundColor':'#ffcc00'});
                }

            }
        });
    });

1 个答案:

答案 0 :(得分:0)

Think about it this way: Since jquery is only happening on the client side, your function is only being run for the person who clicks the "assign" button. You would need to setup some sort of listener outside of that function to listen for that specific change in the database and then have each client act on that change. See something like this: JS/PHP 'listener' to trigger an event