I'm trying to learn how to use mod_perl2 along with Ajax. Everything was 
humming along until it seemed like perhaps Apache had a couple instances of my 
handler in memory, and what I had declared as module variables were existent in 
two different states. It seemed like Apache was handing off to a different 
handler each time my Ajax callbacks were invoked on browser/user input, and the 
handler chosen was somewhat at random. Perhaps I could try to exemplify what I 
was seeing.

package Handlers::Main;
...
    # now I think these aren't necessarily per connection.
    my $ajax_div1a_contents = "<font size=2>default text for div1/a</font>";
    my $ajax_div1a_state = 0; # default state
    my $ajax_div1b_contents = "<font size=2>default text for div1/b</font>";
    my $ajax_div1b_state = 0; # default state
...
    sub handler {
        my $r = shift;
        my $ajax = Apache2::Ajax->new($r);
        $r->print($ajax->build_html());
        return Apache2::Const::OK
    }
...
    sub Show_Form_sub {
        # here I could try to get the request or connection for using notes
        my $self = shift;
        my $r = $self->r;
        my $con = $r->connection;
        my $convar = $con->notes->get('convarA');
        # but I don't think it will help during the ajax callbacks
...
        $html .= '<input type=text name=x id=x onkeyup="fAjax( [ \'x\' ],
                 [ \'div1\' ] );">';
    }
...
    sub fAjax {
        my $x = shift; # this is the field value, not self
                     # don't know how to get the request rec in here
                     # nor the connection
                     # and trying to use module variables like
                     #     those declared above seems buggy
                     # but I would like to know more about the module
                     #     state inside here (for only this connection)
                     #     than just the value of x.
    }

One workaround I imagined was maintaining all the needed state for each 
module-session in a database table keyed by sessionid, but I have the hunch 
there must be a usual way to do this, and that that's not the way it is.

tia

Collin Monahan


      

Reply via email to