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

The function works find with a plan onclick="perlfunction('string','string','results')" problem happends when i am using the setInterval function in javascript. I am not good in javascript and don't have a debugger or editor. This is causing me to find the errors myself. I belive webserver (tomcat) doesn't show the error on the client side (javascript).

Replies are listed 'Best First'.
Re^3: Ajax in perl
by Corion (Patriarch) on Apr 26, 2010 at 07:14 UTC

    You haven't posted any code, so how are we expected to reproduce your problem?

    If you are "not good in Javascript", maybe you should learn that? This sounds a bit like "I'm not good at swimming but I like to win this Triathlon.

    The Javascript Error Console is available in every Javascript-capable browser, at least in Firefox and likely also in Internet Explorer. You will need to learn lots more about Javascript if you plan on developping an application that makes heavy use of Javascript.

    Please read the Writeup Formatting Tips to make your code render and download nicely, thanks!

      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.
        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);

        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.