1

Can I have a value automatically pushed onto a website (using AJAX = JQuery?), when something is done on the server side and python is ready to send it, rather than just in a response to a request by the website.

How do I make Jquery ready to accept this adhoc data?

Tutorial I'm learning from: http://flask.pocoo.org/docs/patterns/jquery/#the-html

VisioN
  • 143,310
  • 32
  • 282
  • 281
user1804633
  • 1,507
  • 2
  • 9
  • 9

2 Answers2

5

Walk's answer is correct, but these days there is another option. Web Sockets can push data from a server to a browser. For some languages (notably Node.js) there are sophisticated libraries for handling web sockets and these often deal with fallbacks for older browsers.

Python has a number of libraries depending on what you need. These two are some of the most popular:

thelastshadow
  • 3,406
  • 3
  • 33
  • 36
1

You can have jquery make the AJAX request and wait for a period of time while the server processes the response and returns it, you may risk the transaction timing out. This is optimal if the responses are quick to return.

Another method would be to have a timed script that polls the server for updates. The server will place the updates for a specific session in, for instance a database or in memory, and then return the results. This is optimal if it's a long running process.

Walk
  • 1,136
  • 8
  • 8
  • Thanks Walk. What would you suggest the method for polling the server should be? (your approach that is most resource efficient) – user1804633 Nov 07 '12 at 00:02
  • Using jQuery to setup a timer and call the ajax function would do the trick. – Walk Nov 07 '12 at 19:20