How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -
i've website developed using phpfox v3.0.7.
now i'm trying implement 'sse(server sent events)' 1 of php files. reference i'm giving below necessary code part of file. file titled process.class.php , present @ location /var/www/module/notification/include/service/process.class.php
present on server having ip http://34.124.40.142/
.
<?php /** * [phpfox_header] */ header('content-type: text/event-stream'); header('cache-control: no-cache'); defined('phpfox') or exit('no dice!'); /** * * * @copyright [phpfox_copyright] * @author raymond benc * @package phpfox_service * @version $id: service.class.php 67 2009-01-20 11:32:45z raymond_benc $ */ class notification_service_process extends phpfox_service { /** * class constructor */ public function __construct() { $this->_stable = phpfox::gett('notification'); } public function add($stype, $iitemid, $iowneruserid, $isenderuserid = null) { if ($iowneruserid == phpfox::getuserid()&&$isenderuserid==null) { return true; } if ($splugin = phpfox_plugin::get('notification.service_process_add')) { eval($splugin); } if (isset($bdonotinsert) || defined('skip_notification')) { return true; } $ainsert = array( 'type_id' => $stype, 'item_id' => $iitemid, 'user_id' => $iowneruserid, 'owner_user_id' => ($isenderuserid === null ? phpfox::getuserid() : $isenderuserid), 'time_stamp' => phpfox_time ); $this->database()->insert($this->_stable, $ainsert); echo "data: notification generated". php_eol; echo php_eol; ob_flush(); flush(); return true; } } ?>
to access file ant event data(i.e. message "the notification generated") wrote following simple html file having source process.class.php
:
index.html
<!doctype html> <html> <body> <h1>getting server updates</h1> <div id="result"></div> <script> if(typeof(eventsource) !== "undefined") { var source = new eventsource("http://34.124.40.142/module/notification/include/service/process.class.php"); source.onmessage = function(event) { alert(event.data); document.getelementbyid("result").innerhtml += event.data + "<br>"; }; } else { document.getelementbyid("result").innerhtml = "sorry, browser not support server-sent events..."; } </script> </body> </html>
but when run file in browser got following error in firebug console : firefox can't establish connection server @ http://34.124.40.142/module/notification/include/service/process.class.php.
now please me telling how make file accessible in javascript code written in html?
thanks.
Comments
Post a Comment