in reply to Re^3: Ajax in perl
in thread Ajax/perl/javascript in perl

Sorry for all the mistakes. This is my first time posting a problem. Find the test code below.
Use CGI::Ajax; Use CGI; use DBI; my $ajax = new CGI::Ajax('report' => \&report); <html> <body> <input type="button" value="submit" onclick="setInterval('report([\'ar +gs__real\',\'args__monk\'],[\'re\'])', 5000)" </body> <div id="re"><div> </html> sub report { my $input1 = shift; my $input2 = shift; $dbh=DBI->connect("DBI:mysql:$db;host=$host","$user","pass"); $re=$dbh->perpare("select * from table where firstname="$input1" and l +asname="input2"); return $re }
This is an example of something I am trying to do. I want this Ajax function to run every 5 seconds to update my html div tag.

Replies are listed 'Best First'.
Re^5: Ajax in perl
by bart (Canon) on Apr 26, 2010 at 08:21 UTC
    To clarify what Corion wrote: your Perl code contains raw HTML. It doesn't work that way, HTML is data and not code. You have to do something with it, likely put it in a string and print it out. For example.

    Furthermore, there are errors in here:

    $re=$dbh->perpare("select * from table where firstname="$input1" and lasname="input2");
    First, it's "prepare", not "perpare". Second, your second parameter should be "$input2" not "input2". Third: you can't just insert double quotes in a doublequotish string, not without backslashes; but fourth: for SQL those should be single quotes instead. And fifth: to guard against SQL injection and just plain errors, use placeholders, not embedded literal values in the SQL!
    $re=$dbh->prepare("select * from table where firstname=? and lastname= +?"); $re->execute($input1, $input2);
Re^5: Ajax in perl
by Corion (Patriarch) on Apr 26, 2010 at 07:37 UTC

    Your Perl code cannot run. There are syntax errors in it (your HTML) and the Perl code has misspellings in it:

    $re=$dbh->perpare( # should be prepare

    Please fix all the errors in your Perl code first, and make sure that the Perl program works without needing Javascript. Then tackle the Javascript problem.