Re: [cgiapp] XMLHTTPRequest / Remote Scripting / AJAX
On Thu, 10 Mar 2005 13:53:48 -0500, Steve Comrie [EMAIL PROTECTED] wrote: I converted their demo app - http://www.modernmethod.com/sajax/sajax-0.8/php/example_multiply.php to one running on my code using C::A - http://www.unobserved.org/misc/rs/ I wish I could see the code. However http://www.unobserved.org/misc/rs/ is done for me. Interesting you posted about xmlhttp. I've been using xmlhttp alot lately using cgi-app. Basically, the only thing I've done was make it so I could pass an argument to the script and it would return XML instead of using TT(template toolkit). sub myrunmode { my $self = shift; my $params = {} return $self-process('mytemplate.tmpl', $params); } sub process { my($self, $mytemplate, $params) = @_; if($self-query-param('xml')) { use XML::Simple; my $xml = new XML::Simple (noAttr=1); $self-header_props(-type=text/xml); return $xml-XMLout($params); } else { $self-tt_process($mytemplate, $params); } } Whats great about this is, for me at least, no code has to get changed to use this and you can use something like REST to access your webapp. Also another thing, with TT you usually need a TON of more data inside the params hash. Then you'd need with xmlhttp. Basically because with TT you're building a whole page, and with xml http you're building a part or section of a page. In my case I was also doing worthless queries etc. So beware of this. In my case I created a wrapper, using cgi-app, around modules that I would normally just include into my application modules. -- Jason Yates [EMAIL PROTECTED] - Web Archive: http://www.mail-archive.com/cgiapp@lists.erlbaum.net/ http://marc.theaimsgroup.com/?l=cgiappr=1w=2 To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [cgiapp] XMLHTTPRequest / Remote Scripting / AJAX
I ran into this, too and thought it would make a great infusion for the Perl Webdev community. I'm still trying to get my head around it, but having it supported in cgiapp would be great, perhaps as a Plugin or something. Here are some other ideas: 1) HTML::Template In the PHP example, they have a ? rs_show_javascript(); ?. Then the backend has to worry about escaping the JavaScript code. HTML::Template already has a nice ESCAPE feature: !-- TMPL_VAR NAME=rs_javascript ESCAPE=JS -- 2) App. Development What would the app look like? How can we make it simple for webdevs? - use WWW::AJAX::Simple; my $app = WWW::AJAX::Simple-new(); $app-expose_function( 'multiply' ); $app-run(); - That was my initial take, but having it as a Plugin sounds tastier. ;) - use CGI::Application::Plugin::SAjax; sub setup { # ... $self-sajax_methods( [ qw( multiply divide ) ] ); } - It'd be neat to do something (prolly more complicated method definitions ala dfv) such that the Plugin can create the JavaScript functions automatically. $self-sajax_methods( { 'multiply' = { 'params' = [ qw( x y ) ], 'reset_value' = 'z' }, 'divide' = { 'params' = [ qw( x y ) ], 'reset_value' = 'z' }, } ); Can you imagine what would happen if Mark/Cees/Michael/Jesse/Sam got ahold of this? ;) I would love to help out on this effort, so please count me in, if you're looking for help. :) - Jason Steve Comrie wrote: Good Afternoon, If you haven't heard of XMLHTTPReqeust aka Remote Scripting aka AJAX it's basically a way for web pages to communicate with the server and return information through JavaScript without having to refresh the page. You can read more about it here: http://www.adaptivepath.com/publications/essays/archives/000385.php and see it in action here: http://www.google.com/webhp?hl=encomplete=1 There are currently some useful applications for AJAX and, I'm sure, lots of superfluous ones too. I'm hopeful that the number of useful ones will grow as the technology becomes more wide-spread and easy to use, which brings me to the point of my post. I stumbled across a site called SAJAX (http://www.modernmethod.com/sajax/) today that has developed a *S*imple AJAX method that can be used with Perl, via their Sajax.pm file. After playing around with it for a while, I was able to strip down their code (actually getting rid of all their Perl code, and leaving only the JavaScript, which I edited and packaged up as a .js file) in-order to figure out exactly how AJAX works and more importantly, how to easily integrate it with a CGI::App based module.pm file. I converted their demo app - http://www.modernmethod.com/sajax/sajax-0.8/php/example_multiply.php to one running on my code using C::A - http://www.unobserved.org/misc/rs/ I invite anyone that's interested in learning more about using AJAX to take a look at my sample app. I've provided source files for download from the page which include: - index.html - remotescript.js ( the required javascript library that does all the XMLHTTPRequest magic ) - rscalc.cgi ( C::A instance script ) - RemoteScriptCalc.pm ( C::A Application Module ) The example uses 2 very simple run-modes, a multiply and a divide run-mode. The divide() run-mode takes advantage of how to handle error messages when communicating with the script remotely. As far as I can tell, I see no problem with including a couple of AJAX based run-modes into an existing C::A module (provided you setup the JavaScript on the calling page properly). Hopefully, some others will find this useful and hopefully be able to use it in their C::A apps. I know I intend to implement it soon for apps where I know the browser requirements are met. I didn't document the code very much, but I kept it nice, clean and organized to help readability. Good knowledge of javascript is needed to hack the remotescript.js file, but you don't need to be an expert in-order to use it. If you want to talk about the applications of using XMLHTTPRequest with C::A I'm sure we can keep this on the list, but if you're having trouble getting my sample code to install or work on your server contact me directly so we don't clutter up the list. I'll try and help out time permitting. BTW - I don't know what the exact browser requirements are however, I just know it works on my WinXP IE6 or Firefox. The SAJAX site might have more info on that. That URL again is: http://www.unobserved.org/misc/rs/ Steve Comrie LEAD SOFTWARE ARCHITECT | OCTANE T: 416.977.2525 F: 416.977.8481 355 ADELAIDE ST. W. SUITE 1B TORONTO, ONTARIO M5V 1S2 WWW.OCTANE.TO - Web Archive: http://www.mail-archive.com/cgiapp@lists.erlbaum.net/ http://marc.theaimsgroup.com/?l=cgiappr=1w=2 To
RE: [cgiapp] XMLHTTPRequest / Remote Scripting / AJAX
Very Fine Work. Thanks for contributing this to the community. Cheers --Fred -Original Message- From: Steve Comrie [mailto:[EMAIL PROTECTED] Sent: Thursday, March 10, 2005 10:54 AM To: cgiapp@lists.erlbaum.net Subject: [cgiapp] XMLHTTPRequest / Remote Scripting / AJAX Good Afternoon, If you haven't heard of XMLHTTPReqeust aka Remote Scripting aka AJAX it's basically a way for web pages to communicate with the server and return information through JavaScript without having to refresh the page. You can read more about it here: http://www.adaptivepath.com/publications/essays/archives/00038 5.php and see it in action here: http://www.google.com/webhp?hl=encomplete=1 There are currently some useful applications for AJAX and, I'm sure, lots of superfluous ones too. I'm hopeful that the number of useful ones will grow as the technology becomes more wide-spread and easy to use, which brings me to the point of my post. I stumbled across a site called SAJAX (http://www.modernmethod.com/sajax/) today that has developed a *S*imple AJAX method that can be used with Perl, via their Sajax.pm file. After playing around with it for a while, I was able to strip down their code (actually getting rid of all their Perl code, and leaving only the JavaScript, which I edited and packaged up as a .js file) in-order to figure out exactly how AJAX works and more importantly, how to easily integrate it with a CGI::App based module.pm file. I converted their demo app - http://www.modernmethod.com/sajax/sajax-0.8/php/example_multiply.php to one running on my code using C::A - http://www.unobserved.org/misc/rs/ I invite anyone that's interested in learning more about using AJAX to take a look at my sample app. I've provided source files for download from the page which include: - index.html - remotescript.js ( the required javascript library that does all the XMLHTTPRequest magic ) - rscalc.cgi ( C::A instance script ) - RemoteScriptCalc.pm ( C::A Application Module ) The example uses 2 very simple run-modes, a multiply and a divide run-mode. The divide() run-mode takes advantage of how to handle error messages when communicating with the script remotely. As far as I can tell, I see no problem with including a couple of AJAX based run-modes into an existing C::A module (provided you setup the JavaScript on the calling page properly). Hopefully, some others will find this useful and hopefully be able to use it in their C::A apps. I know I intend to implement it soon for apps where I know the browser requirements are met. I didn't document the code very much, but I kept it nice, clean and organized to help readability. Good knowledge of javascript is needed to hack the remotescript.js file, but you don't need to be an expert in-order to use it. If you want to talk about the applications of using XMLHTTPRequest with C::A I'm sure we can keep this on the list, but if you're having trouble getting my sample code to install or work on your server contact me directly so we don't clutter up the list. I'll try and help out time permitting. BTW - I don't know what the exact browser requirements are however, I just know it works on my WinXP IE6 or Firefox. The SAJAX site might have more info on that. That URL again is: http://www.unobserved.org/misc/rs/ Steve Comrie LEAD SOFTWARE ARCHITECT | OCTANE T: 416.977.2525 F: 416.977.8481 355 ADELAIDE ST. W. SUITE 1B TORONTO, ONTARIO M5V 1S2 WWW.OCTANE.TO - Web Archive: http://www.mail-archive.com/cgiapp@lists.erlbaum.net/ http://marc.theaimsgroup.com/?l=cgiappr=1w=2 To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: [cgiapp] XMLHTTPRequest / Remote Scripting / AJAX
Hi Steve, -Original Message- If you haven't heard of XMLHTTPReqeust aka Remote Scripting aka AJAX it's basically a way for web pages to communicate with the server and return information through JavaScript without having to refresh the page. Very cool stuff indeed. I converted their demo app - http://www.modernmethod.com/sajax/sajax- 0.8/php/example_multiply.php to one running on my code using C::A - http://www.unobserved.org/misc/rs/ [*SNIP*] The example uses 2 very simple run-modes, a multiply and a divide run- mode. The divide() run-mode takes advantage of how to handle error messages when communicating with the script remotely. I posted about a similar technology on the list just over a year ago [1]. It uses a library called JSRS [2]. I've written a perl module to interface with the library -- it can be found under the JavaScript::RPC namespace [3]. My module works slightly different in that you need to use it as your base class. Also, method parameters are sent to the sub via @_ rather than through the query string errors are reported just by die()ing. (Though, obviously you could write a module to do things similarly for AJAX) You can see these differences in the demo usage [4]. Anyway, I'm glad that this is finally becoming main-stream -- perhaps it will influence the way we write applications. Cheers, -Brian [1] http://www.mail-archive.com/cgiapp@lists.erlbaum.net/msg01593.html [2] http://www.ashleyit.com/rs/ [3] http://search.cpan.org/dist/JavaScript-RPC/ [4] http://search.cpan.org/src/BRICAS/JavaScript-RPC-0.06/demo/jsrpc.pl - Web Archive: http://www.mail-archive.com/cgiapp@lists.erlbaum.net/ http://marc.theaimsgroup.com/?l=cgiappr=1w=2 To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [cgiapp] XMLHTTPRequest / Remote Scripting / AJAX
Jason, IMHO, what the folks at SAJAX were trying to do (with including the javascript code inside the Sajax.pm module) and calling SAJAX::functions from inside your perl code is just way to complicated for no noticeable (at least at first look) reason. I'm sure for more complicated implementations there may be a need for a helper function or module to make sure the returned content gets back to the browser properly. The meat of the technology is really in the JavaScript, not the language that you're using on the server side. That's why I created a .js file to encapsulate the XMLHTTPRequest. The perl code behind it is actually QUITE simple, and in my opinion it should stay that way. I think XMLHTTPRequest integrates *seamlessly* into C::A without any Plugins or additional modules (at least for now). 1) HTML::Template In the PHP example, they have a ? rs_show_javascript(); ?. Then the backend has to worry about escaping the JavaScript code. HTML::Template already has a nice ESCAPE feature: !-- TMPL_VAR NAME=rs_javascript ESCAPE=JS -- I bypassed this step completely by created the .js file and including the following in my template script type='text/javascript' src='remotescript.js'/script 2) App. Development What would the app look like? How can we make it simple for webdevs? --- $self-sajax_methods( { 'multiply' = { 'params' = [ qw( x y ) ], 'reset_value' = 'z' }, 'divide' = { 'params' = [ qw( x y ) ], 'reset_value' = 'z' }, } ); I by passed these steps by creating one standard javascript function that all of your html file based XMLHTTPRequests use to call a server-side script instead of a duplicated block of javascript code for each function that SAJAX currently creates for each one. Really just think of it as a form submit that returns very simple out put to a javascript function already on the page as opposed to returning an entire HTML page. One plausible use is this: I have a screen in my app that allows you to associate a record with a group from a drop-down. If you haven't created a group by the time you've gotten to the edit record screen, you could make an XMLHTTPRequest to your code that created the group (as long as you give the user a Create New Group input box on that page. Your C::A script would receive the request just like it does any other request, create the group, and return the new group id directly back to the edit record page. Now, that page could use a simple block of javascript code to add the new group to the drop-down menu so that the user could select the group, save the record and be done. --- Steve Comrie - Web Archive: http://www.mail-archive.com/cgiapp@lists.erlbaum.net/ http://marc.theaimsgroup.com/?l=cgiappr=1w=2 To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [cgiapp] XMLHTTPRequest / Remote Scripting / AJAX
Hi all, If you haven't heard of XMLHTTPReqeust aka Remote Scripting aka AJAX it's basically a way for web pages to communicate with the server and return information through JavaScript without having to refresh the page. For those interested in using JavaScript to update parts of the page (rather that refreshing it completely) here is a whole (CGI::App-derived) framework built on that idea: http://search.cpan.org/~eric/OpenThought-0.71/lib/OpenThought.pm http://search.cpan.org/~eric/OpenPlugin-0.11/OpenPlugin/Application.pm It uses a hidden frame to communicate with the server (which is what people did before the advent of XMLHTTPRequest, but the idea is the same). I have not used OpenThought, just stumbled upon the link. And since we are at it, has anyone done experiments with building CGI::Apps for Mozilla XUL that they want to share? (This is of course totally non-cross-browser, so not useful for web sites, but could be worth a look for Intranet applications) Thilo - Web Archive: http://www.mail-archive.com/cgiapp@lists.erlbaum.net/ http://marc.theaimsgroup.com/?l=cgiappr=1w=2 To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [cgiapp] XMLHTTPRequest / Remote Scripting / AJAX
Steve Comrie [EMAIL PROTECTED] wrote: If you haven't heard of XMLHTTPReqeust aka Remote Scripting aka AJAX it's basically a way for web pages to communicate with the server and return information through JavaScript without having to refresh the page. You can read more about it here: http://www.adaptivepath.com/publications/essays/archives/000385.php and see it in action here: http://www.google.com/webhp?hl=encomplete=1 [and here] ...SAJAX (http://www.modernmethod.com/sajax/) [and now the CGI::App port, here] I converted their demo app to one running on my code using C::A http://www.unobserved.org/misc/rs/ I invite anyone that's interested in learning more about using AJAX to take a look at my sample app. Nice proof of concept, Steve! I guess this is an (actually old) idea that's seems to have been hitting critical mass lately (probably due to the clever new acronym!) Just a few days ago, I was devouring the examples at http://www.pengoworks.com/workshop/js/gateway/ (the zip code lookup examples rock!) which actually doesn't use XMLHttpRequest at all, but rather a hidden IFRAME (because this code is 5 years old). The concept of non-page-loading web apps has been banging around that long, but I guess Google Suggest and Google maps have just recently pushed the technique to the tipping point. I'm working on app currently that uses JavaScript to load a dozen or so dropdowns, each of which can grow quite long indeed. One client populated the thing with so much data that dynamic JS code had swelled the page weight well past 700K! Fortunately that wasn't as painful as it sounds since the business users of this (non-public) web app all enjoy fast broadband connections, but that, the old fashioned way sure isn't gonna scale! So Google Suggest has got me thinking about dynamically populating drop downs as the user types, with only the incrementally defined subsets of data that they need to see. So I'm really itching to try this out with CGI::App, too! But now I'm not sure if XMLHTTPRequest of this hidden-IFRAME hack is the best way to go. Google maps seem to be using an IFRAME, while Google suggest uses the XMLHttpRequest {sigh}. I guess it doesn't matter now, cross-browser-wise. The link below (almost a year old) says that XMLHttpRequest support has been in IE since IE5, Mozilla since 1.4 and Safari since 1.2 (and dubs the IFRAME trick a hack): Apple Developer Connection: Dynamic HTML and XML: The XMLHttpRequest Object http://developer.apple.com/internet/webcontent/xmlhttpreq.html with it's own Appleesque example (loading an RSS feed of your mission critical I-Tunes) http://developer.apple.com/internet/webcontent/XMLHttpRequestExample/example.html and here's another excellent article from the Apple developer connection, this time a treatment of the hidden IFRAME route, which they call Remote Scripting. Remote Scripting with IFRAME: http://developer.apple.com/internet/webcontent/iframe.html While, here it is called Round-Tripping: http://www.glendinning.org/webbuilder/roundTripIframe/ (which sounds more like something we'd rather not admit we did back in high school...) But whatever underlying technique is used, this is a Whole New Way of thinking about developing web apps, and I'm guessing that, now that the cross browser support is there, we'll be seeing (and building!) a lot of these. -dave - Web Archive: http://www.mail-archive.com/cgiapp@lists.erlbaum.net/ http://marc.theaimsgroup.com/?l=cgiappr=1w=2 To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]