0

I've just created an SSE script instead of polling, i'll use polling as a backup if no sse support though. Problem is, having never used it I can't figure out what is going wrong! I've changed the PHP filethe javascript references to have the correct MIME type and used the correct format of echo 'data: '.$num_rows.'\n\n';

   var originalTitle = document.title; //for title attribute update later

    if (!!window.EventSource) {


  var source=new EventSource("AJAX/get_feed_updates.php?ids%5B%5D=1234567969&ts%5B%5D=2012-12-10+21%3A15%3A04");
  source.onmessage=function(result)
   {
    if (result.data > 0){
    alert (result.data);
     document.title = '(' + result.data + ') ' + originalTitle;

         if (result.data == 1){// no plurals
           $("#refreshFeed").show().html(result.data + ' more news item.');
         }

         if (result.data > 1){ //plurals
            $("#refreshFeed").show().html(result.data + ' more news items.');
         }
         }
}, false);
}

There's the script, i can't fugure out whats happening. The script is got via GET as it shows in the console but I can't see any responses. If i type in the script url directly it works but not via js.

4

0 回答 0