How to dynamically pass a user field value to jQuery? I have a notification bar with a counter, it actually prints the user's "notifications" field value (if it's greater than 0):

&lt;div id=container&gt;
&lt;a href="#" class="activity_link"&gt;Activity&lt;/a&gt;
&lt;?php
global $user;
$user_fields = user_load($user-&gt;uid);
$user_notifications = $user_fields-&gt;field_notifications['und']['0']['value'];
if ($user_notifications &gt; 0) {
echo '&lt;div class=blob&gt;'.$user_notifications.'&lt;/div&gt;';
echo '&lt;div style="display:none"&gt;'.flag_create_link('unmark_notifications', $user-&gt;uid).'&lt;/div&gt;';
}
?&gt;
&lt;/div&gt;


And a jQuery function that resets the value to 0 on click:

    (function ($) {
      Drupal.behaviors.scriptjs =  {
        attach: function(context, settings) {

        $('.activity_link').click(function() {
        $('.activity_menu').toggle();
        $('.blob').fadeOut('normal');
        $('.flag-unmark-notifications .flag-action').click();
        $('.flag-unmark-notifications .unflag-action').click();
    });
    }
   };
  })(jQuery);


The problem is that when a new notification is received you need to refresh the page to see it.

What I've thought to do is to pass the user's "notifications" field to jQuery and update accordingly..

Is this the best way to do it or should I think about using Node JS?

How would you listen for a field value change event and then refresh the counter?
You can use Block Refresh module. Put the notification's content in a block and using this module refresh block in some interval of time. In block template write your own condition or logic.