As mentioned in #catalyst and a few times here, I've been starting to learn and play around with JavaScript in my Cat apps recently, especially using jQuery. I'm wondering if there are general principles for how to integrate JS with Cat.
In particular, I'm curious about the best ways to send data from my controller to my JS. Earlier today in #catalyst I asked about a particular problem--an AJAX routine that calls a URL back in the Cat app to transfer its data. The URL is hard-coded in the JS (which is in a separate file, so I can't modify it directly with TT). In the first version of this particular routine, it worked fine--I called it from a :Local controller method called "sort_list", and I had a relative URL called "update_sort" or whatever, and it called http://MyApp/controller_name/update_sort. When I reused it in another app where it was called from a chained controller, the same bare URL in the JS tried to call http://MyApp/controller_name/sort_list/update_sort, which of course failed. I don't know the best way to handle this. I'd expect that what I want to do is pass a variable like "url_to_call" to the JS, but I don't know how to get it there. I can certainly have a <script> block in my TT file that simply sets the JS variable from the stash, but this feels like a kludge. I assume there's also some way to tweak the controller so that this relative URL will work properly with chained controllers, but this also feels like a kludge. What do people do for this? I should state first and foremost that I'm not and will never be some big JS guru, and I'm not looking to build super-flashy Web 2.0 stuff with huge masses of JS. Thanks. Jesse Sheidlower _______________________________________________ List: [email protected] Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[email protected]/ Dev site: http://dev.catalyst.perl.org/
