Yes, I think you're getting it. Ajax is powerful, but also quite confusing when you first try to get your head around it. You have to think in terms of a hybrid, multi-platform application, since you're really merging at least three distinct technologies into one user experience.
The web.py server and templates do nothing more than deliver STATIC content to a web browser. That's what a web server does. The templating code allows you to make decisions, in python on the server side, based on querystring arguments and such, but ultimately all you're really doing is delivering *code* (html+javscript) to another interpreter (the browser). PHP, Ruby, ASP... it's all the same in this regard - building a page for the browser. Once the request is delivered, the browser takes over. If a user clicks something, it'll be the javascript interpreter that handles that click. Javascript (or jquery) can either a) redirect the user to a different page, b) manipulate things locally or c) submit/receive information via ajax. You gotta remember, ajax is nothing more than a regular http request, however it's *hidden from the user*, and you can handle the results however you like without refreshing the original page. So, a typical workflow: 1. user requests http://localhost/home 2. web.py delivers the home page via render() 3. browser draws the home page html, and processes any onload() javascript 4. (page is now idle, waiting for user interaction) 5. user clicks something, javascript function evaluates what was clicked and decides to request more data 6. javascript creates and issues an XmlHttpRequest (or in jQuery... $.ajax() ) 7. web.py handles the request, let's say it was to /home_tab_2 (web.py doesn't care whether or not this is an ajax request or a traditional page request... doesn't matter... it's just a different url handler) 8. your handler will most likely build some html or json data (your tab content) to send back 9. in the browser, javascript receives the response content from the request 10. javascript updates the page (with element.innerHTML() or in jquery $(element).append() or whatever) I hope this helps, as writing this down really helped me with my first ajax application. S On Mon, Dec 10, 2012 at 9:54 PM, Megha Vishwanath < [email protected]> wrote: > Thanks Shannon, Quick last question: > >> >> The results will be sent to the browser, behind the scenes, via an >> xmlhttprequest object. (The page will not appear to refresh at all - >> that's the whole point of ajax.) Using purely javascript, you then take >> the results of the response and write them into the proper place in the DOM. >> > > So, this means I still render my results to one common template called > schoolpage from all the different data handlers - which the binding > template and call on JS within that to build HTML of the returned response? > > >> This is pretty confusing in pure javascript in my opinion, and I'm not >> familiar with the tab utility you're using. I do know, however, that >> jQuery makes ajax like this a lot easier. > > > I may switch to jQuery, if the one I'm using makes life complicated. > > -- > You received this message because you are subscribed to the Google Groups > "web.py" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/webpy?hl=en. > -- You received this message because you are subscribed to the Google Groups "web.py" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/webpy?hl=en.
