Welcome Guest, Not a member yet? Register   Sign In
How to implement EventSource on Codeignigter app?
#3

It's not the route. Actually, you don't need the route. Whenever the key and the value are the same the route is pointless.

One big issue is the attempt to load a new "job finished" view. Any change to the existing page has to happen in the "message" event handler. So sending back the html of a whole page is not appropriate.

Is your intent to show a new page once the data conversion is complete?

If that's the case, then you need to send a "message" that the onmessage event can interpret as "job complete" and then redirect to the new page using javascript.  While the conversion is in progress you should be periodically sending messages that represent the current state of the conversion process. (How long does this process take anyway?) A periodic update like this usually requires a loop with a timer. You might find this example useful. However, that uses sleep() which probably won't work for you as it stops script execution. PHP does have an Event Class which would do what you need, but it requires an external library and the extension isn't bundled with PHP and so requires installation using a PECL.

You probably don't want to create the "EventSource" until the <form> is submitted. So you will need an event listener to catch that.  You can read about the HTMLFormElement: submit event HERE.

One last thing, you do not need a multi-part form. Those are used when you want files to be sent through a POST. You're not doing that.
Reply


Messages In This Thread
RE: How to implement EventSource on Codeignigter app? - by dave friend - 02-23-2020, 11:33 AM



Theme © iAndrew 2016 - Forum software by © MyBB