CodeIgniter send multiple responses to client - codeigniter

Is there any way when the client sends a request to the CodeIgniter server that it can respond with multiple responses?
For example, this can be a file upload to show how the file is processed in the backend.
Can this be done with an ajax request or do I need sockets for this?
EDIT:
Example situation here
I send a data object to the CI backend to be saved. Let's say on the
backend the following functions has to run on this received data
Inspect data to be secure
search for any similar data
Save data
Create a page based on the data
add some default images to this new page
As you see, these functions may take more then 5 seconds to execute.
Do I need a response from the server every time a task from the list above is completed? Does that make sense?
Another example would be when task 1 is complete the server will send a response saying that task 1 has completed. So the user knows that something is going on.

Related

Trouble using Websockets with Julia

I am trying to connect to an API that uses websockets. I need to do the following:
Connect to the websocket using a given URI
Send a login request
Send a request for the required data stream(s)
Store the returned streamed data in an array for immediate processing (the array will be continually updated while data is streamed)
When finished collecting data, send a logout request
I have a general understanding of websockets, but have never tried to connect to a websocket. I have read through the “documentation” for packages HTTP (which I have used before), WebSockets, and DandelionWebSockets. Each has left me scratching my head trying to understand how to implement the above tasks.
Would someone please help by showing me, line-by-line, how to set up the above tasks and also explain why each line or function is used? (Assume I have the correct URI, login, data, and logout request formats.)

Flask AJAX: send interim data to front end during a route

I've made an app using Flask, that has a backend process that is initiated by the user.
When the user initiates the process, some data is sent to Flask via jQuery AJAX, which is then processed, and the results are returned.
This process can take between a few seconds and up to around a minute, so I have a 'please wait' modal on the front end while waiting for the AJAX response from the backend.
Is there a way I can send interim data to the front end, to update the 'please wait' modal, while the backend process is doing its thing?
The backed process performs iterations until it is satisfied. So ideally I would like to be able to display to the user how many iterations it has performed.
Initially I thought that there might be something within Flask's 'flash' message feature. But it seems that this relates more to redirects in a route, rather than AJAX calls to a route.
Any suggestions would be appreciated.
Cheers,
Hugh
Yes you can do it, but not with AJAX, becuse the HTTP comunication is only client to server, so you cant update asynchronously your clinent with HTTP, so you need to use other protocol. I highly recommend to use SocketIo, this protocol allows to you to send mensagens asynchronously from server to update your front, becuse this protocol persist the user in server. With this protocol(for example) you can make a chat room, like WhatsApp. for more information see Documentation SocketIo Flask Extension

How do I trigger an amp-analytics request when an AJAX request has finished?

I work at an analytics vendor and we're looking into supporting AMP. I'm looking into beaconing data using amp-analytics. I've got the default trackPageView working from the example in the docs. I get a POST request sent to my server when the page is loaded.
However, one of our use cases is sending a beacon after an AJAX request has completed on the page. The idea is that our customer performs an AJAX request to one of our APIs and gets back some data. Some of that data is used to add elements to the DOM and some of that data is sent back to us which acts as a beacon type in our system. One thing I thought of was since that second piece of data is coming from us and then being sent back to us, we could just send it between our services internally and not have the browser need to send it to us at all, but there are a few issues that prevent us from doing this:
The API in question is high traffic and has caching implemented. There are many more requests being made by browsers than being received by our API's server, and we want to track them all.
We also want to track data such as browser user agent, so we need that request to be sent by the browser, not our API server.
I have a few challenges here with implementing this in AMP:
The AJAX request would be performed by an amp-script element that our customer would put together. Since amp-scripts are very sandboxed, would this cause issues having the contents of an amp-script interact with the AMP runtime?
I don't see any triggers in AMP docs that I could use to have the amp-analytics request sent when the AJAX request completes.
Usually the questions I put together on StackOverflow are more direct, but I'm mostly confused right now on how to implement this with AMP or whether it's even possible to implement it with AMP at all.

How to execute a service that check the status of backend data at all application use AngularJS

Like it's mentionned on the title, I'm trying to create an Angular service that will be used like a listenner on the backend, It will check if the backend finished calculating a list process and return what is not finished yet.
For example: reexecute the verification every 5 seconds while the user is still on the application interface.
Part of the difficulty of doing this will be to have your backend report the progress of its calculation, but, assuming you have that figured out, the frontend portion seems like it could be fairly straightforward.
Your service could, e.g., with the $http service, make repeated requests to some backend controller until the backend returns a sentinel to signify it has completed calculating.
The frontend program flow would be like this:
Make request to backend
Wait for response
When response is successfully received:
Update frontend scope/vars/view/whatever with received data
If response contains completed sentinel, stop making requests
If response doesn't contain completed sentinel, repeat this process (after some delay)
I made a JSFiddle with a very simple example of what I mean. Every three seconds it makes another request to the backend (using the $timeout service).

Grails: server-to-client notification

I'm building a Grails app which queries several API's across the Web. The problem is that this queries are very time consuming and it is really annoying for the user to click one button and wait so much time without nothing changes in the page.
The basic architecture of my app is, when the user clicks the button, the client side performs an Ajax request with Prototype library to the server side. The server side, then, connects to the Last.fm API and retrieve a list of events. When the server side is finished populating the list with events it sends a JSON response to the client side which allows the client side to create markers for each event on a Google map.
What I want to achieve is, instead of waiting for all the events being retrieved from the API to send the JSON response, the server side sends a JSON response as soon as it retrieve one event, allowing the client side to populate the map while other events are yet being retrieved.
Any ideas how can I implement this? I read about the concept of Ajax Push but I'm not sure if it is what I need.
Thanks for the help!
There is no way to open a listening connection on the client that your server might connect to. Instead, what you need is a connection to the server that is kept alive and can be used to receive events. This way, you could directly return the "action" request and inform the client through your persistent event connection once the last.fm request was completed.
That said, the way I would implement is using ajax keep alive.
Take a look at cometd plugin.

Resources