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