0

I am doing long pooling using php, (which work fine) and assigning it's output JSON to fullcalender event source.

My js code

var source = new EventSource(WEBROOT+'model/applongpooling.php?start=1476037800&end=1476642600');
source.addEventListener('message', function(e) {
     console.log(e.data);
     $('#calendar').fullCalendar( 'removeEvents');
     $('#calendar').fullCalendar('addEventSource',e.data);// here i am getting error
}, false);

My php pooling code.

<?php
     header('Content-Type: text/event-stream');
     header('Cache-Control: no-cache');
     function SetAppointment(){
       //my logic which is working fine and giving me correct result

         echo 'data: ' . json_encode($res) . "\n\n";//code to get output
         echo PHP_EOL;
         ob_flush();
         flush();
     }
 do {
 SetAppointment();
  sleep(15);

  // If we didn't use a while loop, the browser would essentially do polling
  // every ~3seconds. Using the while, we keep the connection open and only make
  // one request.
} while(true);
?>

In console i am getting correct output.

Consol Output

I am getting Error,

Error

In another js i have also assign event source to fullcalender,

eventSources: [
        {
            url:'model/appointments.php',
            editable: true,
        }
    ]

so my question where am i wrong, any suggestions? why am i getting such error?

Archish
  • 850
  • 8
  • 32

1 Answers1

0

I don't think your error message can possibly match your EventSource() call, so are you using Apache with rewrite rules (or something like that)? If so, the bug is in those rewrite rules. (I was going to ask what WEBROOT is, but the more I think about it, I don't think it matters.)

Reason: Your EventSource call URL ends in "model/applongpooling.php?start=1476037800&end=1476642600". But your error message ends in "back_color%22:%22?start=1476037800&end=1476642600". I.e. everything in front of the ? has been changed.

I'd expect all that noise in the URL is what is causing the 403 error. E.g. Maybe it is trying to access some directory that doesn't exist? But, a rewrite call could also be explicitly be issuing the 403.

Darren Cook
  • 27,837
  • 13
  • 117
  • 217
  • yes i am doing url rewriting, but how that can cause me error, please explain me. :( – Archish Oct 29 '16 at 05:21
  • @Archish (I assume) the rewritten URL is a URL that does not exist, or is invalid in some way. So it triggers the error you see. – Darren Cook Oct 29 '16 at 07:59