Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^3: Using CGI::Ajax for multiple form buttons/divs simultaneously

by dsheroh (Monsignor)
on Mar 20, 2018 at 11:04 UTC ( [id://1211294]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Using CGI::Ajax for multiple form buttons/divs simultaneously
in thread Using CGI::Ajax for multiple form buttons/divs simultaneously

Yeah, that is the one major annoyance with CGI::Ajax, it kind of takes over completely. When you call build_html, it actually spits out a big mess of javascript into your page to make its magic work, and then, when you call one of its javascript helper functions, it intercepts that and takes over the back-end request handling, bypassing whatever your normal dispatch method might be. Towards the end of my time using CGI::Ajax, I delved into that and managed to at least partially unravel it and figure out how to bypass some of the magic, but I don't recall any of the details, only that I did it.

These days, I'm using Dancer and Dancer::Plugin::Ajax, which requires me to manually write a little bit of javascript to invoke the ajax functionality, but it's much more transparent and fits into the rest of the application's framework, so I feel it ends up being a lot easier to work with overall. But that might not be an option for you if you're already dealing with legacy CGI scripts and aren't in a position to migrate to Dancer.

  • Comment on Re^3: Using CGI::Ajax for multiple form buttons/divs simultaneously
  • Download Code

Replies are listed 'Best First'.
Re^4: Using CGI::Ajax for multiple form buttons/divs simultaneously
by Polyglot (Chaplain) on Mar 21, 2018 at 03:31 UTC

    To help me remember this myself in the future, should I seek to utilize CGI::Ajax again, I wish to make the following response to what you have mentioned above.

    Everything must be executed from within the &main subroutine. Anything else will fall outside of the purview of Ajax upon callback from the client.

    I had organized my code, as I usually do, by taking care of preliminaries before running the main subroutine--such as collecting my form inputs and setting up default values to certain variables. But instead of "compartmentalizing" things like this, and running them in their necessary A-B-C order, with Ajax, I have learned I must "nest" everything into the main subroutine.

    It seems someone could update the Ajax explanations, which I think I have read several times without realizing this fact, with a little more clarity. The TIMTOWTDI philosophy seems rather narrowed by the use of CGI::Ajax, for the code must be structured in just the right way to make it work.

    As for the "big mess of javascript," I have found CGI::Ajax far less unwieldy than jQuery and similar options which seem more popular. I'm happy with the small amount of JavaScript that the Ajax adds to the page.

    Blessings,

    ~Polyglot~

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1211294]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-18 12:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found