modified: 2020-02-09T16:47:20+01:00

Jybrid has Event/Emitter methods, they triggers on defined positions during an Request-Response Cycle. This Events are NOT DOM events.

In Xajax, the emitters had to be integrated directly via Javascript. Jybrid allows these Javascript functions to be integrated directly via PHP. Several emitters can be added to an event simultaneously. This construction follows the concept that Javascript can be controlled with simple PHP functions as far as possible without having to be completely clear about the spelling and anchoring of the individual Javascripts every time. This is largely automatic.

You can set Emitter global in jybrid. You can set Emitters per request. You can combine core an request emitters. You can also let it be ;-)

Event-Name description core-event per-request event
onRequest Directly during the jybrid.submitRequest x x
onSuccess Response http code was an success code (200). It does not tell something about processing the response x x
onBeforeChallengeRequest before the request will be send again but now with credentials x x
onBeforeResponseProcessing after an Response Successfully received the jybrid response processor will start to handle all response-parts such as jyb.html() x x
onComplete All response commands was processed [oRequest] x x
onFailure Response http code was an alert code between 400 and 599 [(int)'error-code-from-server',oRequest] x x
onFailureResponse Response http code was an alert code between 400 and 599 [(int)'error-code-from-server',oRequest] x x
onFailureResponseProcessor Response was successfully, but jybrid has not detect an response-processor to handle the response x x
onFailureRequest Jybrid has catch'd an error during the send method. jybrid has per default 4 tries to send request['e, error-object'] x x
onFailureRequestFatal ...after the 4 tries give up, with this final fatal event ['e error-object'] x x
onResponseDelay Jybrid script can be noticed, that the response is delayed [oRequest],responseDelayTime x x
onExpiration the jybrid script can be noticed that it dont want wait anymore for the response [oRequest],expirationTime x x
onFailParseResponse the response was successfully received from server, but the json-response-format was corrupted x x

Global Jybrid Emitter

You can create a set of different emitters. These emitters are then responsible for all requests. This is especially good for "spinners" and other request status messages that the user of the website should see. Here you can also catch bugs 400 and 500.

// Emitter as body only
$onRequestEmitter = <<<EOT
    jybrid.html('protocol','<p>onRequest: Request is started</p>');
    jybrid.$('waiting').style.visibility = 'visible';

// Emitter as complete function 
$onCompleteEmitter = <<<EOT
function() {
    jybrid.prependNode('protocol','<p>onComplete :: Response was completely processed<br/></p>');
    jybrid.$('waiting').style.visibility = 'hidden';

// You can also add later an emitter to the special event
$onRequestForgottenEmitter = <<<EOT
    jybrid.html('protocol','<p>onRequest: I had have forgotten my Emitter but set him later ;-)</p>');

// Adding the emitter content 
       ->addEmitter('onRequest', "function(){{$onRequestEmitter}}")
       ->addEmitter('onComplete', "{$onCompleteEmitter}");
       ->addEmitter('onRequest', "function(){{$onRequestForgottenEmitter}}")

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <title>Schematic Emitter | jybrid Tests</title>
    <?php echo \Jybrid\Scripts\Generator::generateClientScript(); ?>

Per Request Emitter

Maybe you have requests that need an extra emitter. For example, for uploads or other things. Then you can set each request individually and store the appropriate emitters for this request only.

$testFormExpirePerRequest = \Jybrid\Factory::register('testFormExpirePerRequest');

/** Delayed */
$onResponseDelayEmitterPerRequest = <<<EOT
jybrid.prependNode('protocol','<p style="color: greenyellow">onResponseDelay Response was delayed '+jybrid.config('responseDelayTime') / 1000+'seconds</p>');

// you can set the per request emitters before jybrid global emitters
$testFormExpirePerRequest->getEmitters()  ->addEmitter('onResponseDelay', $onResponseDelayEmitterPerRequest)
    // tell jybrid that you dont want use the global onResponseDelay for this request.

In the example above you can see that the emitter generation is the same as in the jybrid global emitters, but is only applicable to this request.

setIgnoreSignal ('string')

This method is relatively simple to explain. Hereby you instruct jybrid, if an "onResponseDelay" emitter is set globally in jybrid, to ignore it and to use the request's own emitter exclusively for this request. This ignore signal only affects this request. The ignore signal does not remove any "onResponseDelay" emitter present in jybrid."


$testForm2perRequestEmitterIgnoreAllGlobalEmitters = \Jybrid\Factory::register('testForm2PerRequest', ['method' => 'GET']);

In this example you get all set global-emitter names and set these emitters to ignore. All emitters set up to this call are taken into account.

further reading ajax examples

@see schematic-emitter.php

@see schematic-emitter-per-request.php