0

Is there a way to make this script run in real-time, rather than using setInerval()? I do not know where to begin.

$(window).load(function(){
setInterval(function(){
var username=_userdata['username'];
var username=_userdata['username'];
$.get('/notification.forum',function(data){
     var b= data.unread;
    if(b >= 1){
      var c = data.store;
      for(var keys in c){
        var d = c[keys];
       if(d.read === 0){
        var e= d.text.type;
        var from= d.text.from.name;
        var topic = e===7 ? "in the topic "+d.text.post.topic_name.replace(/-/g,' ') : "";
        var type= Notify(e);
          createNotifcation('http://i.imgur.com/LPVUvcf.png',username + ' you have a new notification!',type + " from "+from+"  "+topic);
       }
      }
     }
   });
},5000);
   });

Edit: I found this:

function listen() {
    $.get("/mylongrequestfile", {}, function(data) {
        $("#mydiv").html(data);
        listen(); // then launch again
    }));
};

How to include it into my script ?

  • Take a look at [long plling](http://stackoverflow.com/questions/333664/simple-long-polling-example-code) – Michael Kunst Oct 21 '13 at 15:04
  • I looked at it, but i can't understand. Can you show me an example, on my code ? :D Thank you very much for response! – user2816226 Oct 21 '13 at 15:06
  • possible duplicate of [Is there some way to PUSH data from web server to browser?](http://stackoverflow.com/questions/19995/is-there-some-way-to-push-data-from-web-server-to-browser) – Quentin Oct 21 '13 at 15:08
  • may be instead of fetch mode ,you can try the server push mode.just a suggestion. – ohmygirl Oct 21 '13 at 15:09
  • Well.. but how to ? I'm just a newbie in Javascript and jQuery.. and this is too hard.. for me. :( – user2816226 Oct 21 '13 at 15:19

0 Answers0