RA Jones wrote:
> Ron Savage wrote:
>> On Wed, 08 Nov 2006 20:43:36 +0000, RA Jones wrote:
>>
>> Hi
>>
>>> Well, I could throw in a couple of (slightly off-topic) AJAX
>>> questions if anyone cares to field them, or have we had enough of
>>> that topic recently?
>>
>> Throw them in (aka I'm bored...)!
> 
> That's what I wanted to hear! In one of the previous discussions about
> getting AJAX working it was suggested that a major advantage of using
> the js libraries such as JQuery and prototype over CGI::AJAX was so the
> browser could cache the code blocks and not have to re-load on each page
> refresh. However, I found a limitation here in that I have to hard-code
> the url containing the AJAX function, whereas with CGI::AJAX I can pass
> it as a parameter from the script using the CGI.pm url() function,
> meaning I can run my apps as cgi or mod_perl without needing to change
> anything. This is actually quite a long-winded way of asking if there is
> a javascript equivalent to the CGI.pm url() I could put in the js block?

I'm not sure I completely understand what you're looking for here, but if you
want an Ajax call to submit back to the same url you're page is coming from,
then window.location will contain that.

But usually what I do when I want to use the same function on different urls is
make the url an argument to the function, and then in my template, where I call
the function, I pass in the url from the Perl side. Something like this in TT
template:

  <script type="text/javascript">
    do_something_cool('foo', '[% USE url("/some/url", mode="cool") %]');
  </script>

> Secondly, having managed to make the basic div replace functions work
> nicely with AJAX, I'm trying something a little more adventurous - how
> to populate a drop-down menu depending on the selection of another
> drop-down menu. I can make it work with the following, but it feels wrong:

I wouldn't say it's wrong, but yeah it does seem a little weird to create a new
select box on each change rather than just changing the values in the 2nd select
box.

> And all the code for generating the select block (ie popup_menu()) is
> done in the populate_clinicians() sub in the main application, instead
> of in the template. Yak! But it works. Please tell me there's a better way.

I would probably have the server code emit JSON (using the handy C::A::P::JSON
plugin) and then have the client side JS take that JSON and empty out the target
select and add the extra values.

-- 
Michael Peters
Developer
Plus Three, LP


---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/[email protected]/
              http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to