Thanks. I get it now. For some reason my mind was clearly clouded with only using Dancer the way I had been. On 5/1/2015 3:55 AM, Hugues wrote:
Hello from you html code you can call a route, and this route can call a perl script , not directly a perl script see this example
My route:
use Dancer::Plugin::Ajax ajax '/example/add' => sub {
my $parm1 = params->{'param1' } // undef; my $param2 = params->{'param2' } // undef; my $param3 = params->{'param3' } // undef; ....
my $cmd = "/usr/bin/sudo /home/example.pl &"; my $result = `$cmd`; warning $result; $result=decode('UTF8',$result);
if ( $result ) {
return template 'prelevement/list' => { show_warning => "Erreur<h4>$result</h4>", };
} else {
return template 'prelevement/list' => { show_success => "Calcul <h4>please wait </h4>", }; }
};
My js jquery code in my template ( use class="Example" )
$(".Example").click(function(e){ var param1 = $(this).attr('param1'); var param2 = $(this).attr('param2'); var param3 = $(this).attr('param3'); var DATA = "param1="+param1.toString(); DATA += "¶m2="+param2.toString(); .....
.....
// fonction Ajax. if ( Statut != 'Ok' ) { $.ajax({ url: "/example/add", dataType: "JSON", data: DATA, success:function(data){ // Ne changer la couleur du bouton que pour info if (! BoutonCouleur ) { $('#'+Name).removeClass('btn-default').addClass('btn-success'); $('#'+Name).html('Ok'); } }, error: function(data) { $('#'+Name).html('Erreur'); $('#'+Name).removeClass('btn-default').addClass('btn-danger'); }
}); } });
Le 01/05/2015 10:56, WK a écrit :
Hi!
2015-04-30 1:12 GMT+03:00 John J. McDermott, CPLP <jjm@jkintl.com>:
In a template I invoke (successfully) from a Dancer2 path I have some jquery that works outside Dancer2: Like Andrew pointed, you don't call anything from template, you use template to generate HTML-page, which contains javascript and client/browser makes separate request to get some content from server. This content could come from other route or from other server, whatever. So, instead of script data1.pl seems reasonable to have a route in your Dancer app, which answers to those requests.
Client side (javascript in browser) does not know anything of your serverside content generation, so templates do not matter here.
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
-- John J. McDermott, CPLP Learning and Performance Consultant jjm at jkintl.com 575/737-8556 Check out my security blog posts <http://cybersecurity.learningtree.com> Add an A for the Arts To STEM and get STEAM and a strong engine to move forward.