Reputation: 813
Is it possible with AJAX and Django as the server to have a user's JS make a AJAX request and then have Django respond with what the user requested at a much later time, i.e. when the server has what the user's JS wants?
My idea:
-AJAX requests for object
-Django caches request
-When object that user wants it available, Django signal tells
view to respond to that request with the object
However, I don't know how to allow the JS script to continue on doing other things and then attend to the server's response when it gets it, or to have the AJAX NOT count the server's not responding with the object (or at all) it wants as an error. Is this possible WITHOUT having the JS infinitely loop AJAX requests until it gets what it wants? Could this be done with Django just giving the user the objects when it has them without the AJAX requesting them all?
Upvotes: 0
Views: 81
Reputation: 918
I suppose you are looking for heavy backend processing job which sends results when processing is complete. So for that you can opt for any of the below mentioned process
Long polling - here you can do periodic ajax calls to check if the processing is complete and once its complete you can show the result and stop the periodic ajax checks.
Web sockets - this is better approach as per me. django-websocket-redis is the library which I used to achieve the same. The library has good enough documentation to get you started.
Hope this helps you. :)
Upvotes: 3