I recently started using
ExtJS, with
CGI::Application and
JSON. It works nicely, and abstracts away a lot of the pain of cross-browser compatibility, though the large file size can be a problem (there are other, lighter toolkits that may better serve your purpose). Here's a 30 second example that gets you AJAX style updates:
callbackFunction = function(options, success, response) {
if (success === true) {
var data = Ext.decode(response.responseText);
doSomething(data);
// or
Ext.get('contents-div').dom.innerHTML = response.responseText;
}
else {
Ext.MessageBox.alert('Error', 'Something blew up.');
}
}
Ext.Ajax.request({
url: '/path/to/cgi',
callback: callbackFunction,
params: { rm: 'ajax_function' }
});
The Perl part, assuming you've tagged this sub as a runmode:
sub ajax_function {
my ($self) = @_;
my $data = doStuff();
# or you could return HTML
return $self->{json}->objToJson($data);
}
It has other cool stuff built in, like the ability to automatically generate fields and labels for a form, and bind the validation and submission to callback functions, visual effects, data stores and interfaces for all different kinds of sources... it actually got me interested in learning JS. Pretty cool stuff.
-
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.