Reputation: 568
I'm having a little trouble with something simple I think. I've got a Perl script that already contains a bunch of functioning JQuery. I was hoping to use .blur and .get to run an email validation sub in Perl immediately when the user leaves the email address field. However, I can't seem to connect a Perl script and the JQuery call together. So I've simplified as much as I can just to try to get it to function. Basically, the user leaves the input field, the script is called, simply prints something and I have Jquery through an alert.
JQuery
$('#billemail').blur(function() {
$.get('ajax_email_check.pl', { 'email': $('#billemail').val() }, function(data) {
alert ("Billing email is "+data+"!");
});
});
Perl
#!/usr/bin/perl
use warnings;
use DBI;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
require "./lib/servervars.pl";
require "./lib/common.pl";
my $email_address = param('email');
#my $email_valid = &check_email($email_address);
#if ($email_valid) {
# $output = "Success";
#}
#else {
# $output = "Fail";
#}
print "Success";
Of course if I remove the .get line and closing tags, the alert is triggered upon the field losing focus. Thanks for the help!
Upvotes: 1
Views: 145
Reputation:
Your Perl script (at least the version you've posted) doesn't output a content type header. That's the very least a CGI script must output: the response headers, an empty line signalling the end of the headers, and optionally the content (the string success
in your case), e.g.
print "Content-Type: text/plain\n\n";
if (email_is_valid()) {
print "success";
} else {
print "error";
}
Upvotes: 4
Reputation: 19539
Why have you escaped the $
here?
$.get('ajax_email_check.pl', { 'email': \$('#billemail').val() }
^^^^^
At the very least that'll probably prevent you from getting your value out of the billemail
element (input?).
More importantly, you're mis-matching quotes, so your JS at large is invalid:
alert ("Billing email is '+data+'!"); // <-- Need double-quotes
^^^ ^^^
Try fixing that and see if you get a better result.
Upvotes: 1