Question:
I want to write an AJAX app where some function is triggered by the server rather than the client. Possible?
Joe
2007-03-12 05:51:10 UTC
I was thinking of doing this through a polling method in the client but it would be better if the server could automatically send new data when it was ready.
Three answers:
Martyr2
2007-03-12 09:45:50 UTC
Well it is possible but actually counter intuitive to what AJAX really represents. The idea is that things are done on the client to speed up display as well as take the load off the server side.



I would go with the polling method myself and most people do, but you could accomplish this server triggering the method by setting up a synchronous connection rather than asynchronous like most AJAX apps. Remember when you establish the connection via the Open method and you have that optional third parameter which is a boolean value true or false? It defaults to true but you can specify false and it makes your javascript actually wait for the server to respond before proceeding with the rest of the script.



The trick to this is that you should make this function separate from the rest of your processing. Make one connection for your usual stuff and this other connection essentially locked to the server until it responds.



I am not quite sure if it times out after awhile, but in that case you can detect the close and reopen it again.



Its not the greatest of solutions but with a bit of tweaking you can make it behave like you want. Again I would go with the polling because you will have much more flexibility in that and it fits the structure of a server servicing a client at a client's request.



I have put a link to a document that may help explain the synchronous connection option a bit better. Many programmers consider the synchronous process a bit of bad programming but if it is there, why not use it?



Good luck with this.
jake cigarâ„¢ is retired
2007-03-12 11:26:15 UTC
the normal method of the browser hitting the server is the only way to do it.



BUT (this is the good part)



Because it is asynchronous, there is nothing that says it has to be quick!



do a ajax call, the host does not respond unless it has new instructions for the browser. You can have it wait (not a normal behavior).



on the browser, you have to deal with LOTS of timeouts, and after the timeout, you try again.



so with a little setInterval and intelligent timeout handling, the browser takes instructions from the server!



this is a great way to do a chat program.



I use modperl on my server, and http://jquery.com javascript library. It's not that hard!!
?
2016-12-02 02:15:50 UTC
it may't be finished in Ajax, because Javascript has no how you may do audio capture.. the in undemanding words real thanks to do it (outdoors of the clumsy java) is to apply a custom Flash ingredient. Flash has the convenience of both beign able to regulate and list from an connected mic, plus it gives you community outfitted in streaming...


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...