NB This is not a duplicate of this - it's about asynchronous returns.
I doubt very much whether this is going anywhere, but it could be useful so I'd like to know if there might be some answer.
I send a POST to my server (PHP) ... in response my PHP executes several MySQL queries in succession and gets some results, from each query. At the moment I'm packaging all these results up as one JSON object, echoing back, and obviously I have to wait until all these statements have been executed until I can return all results.
But I'd like to send these results back as several JSONs in succession, i.e. as the results of the queries are delivered. It appears that the AJAX mechanism can only cope with one batch of returned text (JSON or plain text or whatever) and then it ends. But it'd be nice if, instead of that, this communication line between the server and the client could "stay open".
In the Java world there's something comparable: SwingWorker
, which is capable of "publishing" "chunks" of objects from a non-Event Dispatch Thread to the EDT: in effect a "wormhole" between one thread and another is kept open and it's very useful.
In the JS world it appears that the only alternative strategy to sending all results back at once is to do multiple AJAX calls... and in that case if one SQL query is dependent on the results of the previous one this is potentially going to have a big performance hit.