Frederik Krohn
Frederik Krohn

Reputation: 5

php, ajax: two ajax responses (non-synchronized)

So, I have an ajax-POST from the client, that asks for some information. I am thinking about letting a php file first perform a fast task that sends back just a number and after that perform a background task that takes a bit more time and sends back an array.

I wondered if it's possible to send the two responses separate - once they are ready. If it is, how would I handle it on the frontend with javascript?

Upvotes: 0

Views: 21

Answers (1)

Marcell Bolubás
Marcell Bolubás

Reputation: 134

Typical HTTP can only send responses in a Request->Response manner.

What you may be looking for is WebSockets, which keeps a connection open for further messaging from the server.

https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API

Upvotes: 1

Related Questions