Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I am not sure what other fellow monks' experience is with the AJAX perl module but myself so far, have managed without it, successfully producing beautiful and succinct code.

The first thing I needed were server-side perl CGI scripts responsible for querying DBs and sending data back to client.

Secondly, in all my HTML files I have a small javascript function for POSTing or GETing form data to my CGI scripts using AJAX. Such functions (using jQuery OR NOT) can be found on the net, for example here is one random script using pure javascript (I have neither used nor tested it): https://wp-time.com/ajax-form-pure-javascript-without-jquery/ . Let's call this function doAjax(params, url)

Thirdly, I create higher-level javascript functions responsible for making a POST/GET request (via the doAjax()) and if/when data is received, filling the appropriate DIV or appending to the appropriate UL list, etc.

The procedure is the following, in a single HTML page you have one or more buttons which onClick() will initiate a POST/GET to one of your CGI scripts. When pressing the button in your HTML for, say, doing X, you supply the POST/GET params and also a destination DIV. Then you call the higher-level javascript function I mentioned, let's call it doX(params, destination_div). The doX() function will first call the doAjax() which will have a callback which will be called when data from your server-side CGI script has been received by the client's browser. This is where "filling the content" part of your doX() function starts. You already gave it a destination DIV or UL, it has got the data from the server and so it goes and adds the content in your client's current HTML page (without reloads etc.) by the magical DIV.innerHTML = "<b>voice from the bush</b>"

Because of its asynchronous nature, it is possible for one single HTML page, after it has been loaded in client, to contain buttons for user to request data from server CGI scripts (when I say buttons I mean POST/GET forms or just buttons with an onclick() method calling the doX() functions), data arriving and HTML page's content changing without page reload. In effect you can have a complete surfing session without ever leaving or reloading your current HTML page!

In my experience, it is possible and easy to do AJAX without jQuery and CGI::AJAX. I would first go down this path before using other modules. I have gone down that path in the past and it was success.

A word of warning: Ajax's eventual fate was a tragic one. Here is how Exekias saw it 2500 years ago : https://en.wikipedia.org/wiki/Suicide_of_Ajax_vase#/media/File:Exekias_Suicide_d_Ajax_01.jpg


In reply to Re: Using CGI::Ajax for multiple form buttons/divs simultaneously by bliako
in thread Using CGI::Ajax for multiple form buttons/divs simultaneously by Polyglot

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-19 14:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found