I would like to make an Ajax request to the server, which replies a job status and result. If the status is “Error” or “Ok”, the client should show the result (containing HTML code) to the user. However, if the status is “Waiting”, the client should wait for a few seconds and then automatically send the same Ajax request again. This should continue until it either times out or gets a “Error”/”OK” message.
Any idea for a solution/code snippet like this? I am currently using Rails, JQuery, and Prototype. Many thanks.
Mountain
You can do like
That would initiate a
self-executing anonymous functionwith an ajax request. If the returned string equalsWaitingit will set a timeout for 5 seconds and calls itself again.