how to do client side sorting using querystring in hyperlink associated with the table header using Perl?

后端 未结 2 1568
囚心锁ツ
囚心锁ツ 2021-01-29 16:50

Hello everybody i hope everybody is doin well, Actually i have a table in which i fetch the data from sqlite database,i have done the paging and filtering for the grid using per

2条回答
  •  轮回少年
    2021-01-29 17:19

    This is not an answer to your question, but general advice. Therefore, I have made it community wiki.

    Please stop writing CGI scripts for a while until you understand why your script has serious problems.

    You have:

    use CGI;
    use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
    # ...
    my $query = new CGI;
    my $q = new CGI;
    

    First, note that you need to initialize a CGI object only once. Avoid indirect method calls:

    my $cgi = CGI->new;
    

    I know the CGI.pm docs use $query but I find $cgi to be more meaningful.

    That is a good step. Almost all CGI scripts should use well established libraries rather than homebrew code. However, after that good first step, you do:

    print "Content-Type: text/html\n\n";
    $query = $ENV{'QUERY_STRING'}; 
    @list = split( /\&/, $query);  
     foreach (@list) {
      ($var, $val) = split(/=/);
      $val =~ s/\'//g;
      $val =~ s/\+/ /g;  
      $val =~ s/%(\w\w)/sprintf("%c", hex($1))/ge; 
      ($var, ' = ', $val,); 
     }  
    

    There is no reason to engage in cargo-cult practices. Your CGI object already has the parameters passed to the script.

    Also, you should declare your variables where they are first used as opposed to dumping all of them at the script.

    Use CGI.pm's header to send the header. You have:

     print <
     
     
     
     
    END_HTML

    which makes no sense as you have sent a complete HTML document before doing anything else in the script.

    The rest of the code cannot change what you have already sent.

    Put your HTML in a template. Personally, I like HTML::Template for the clean separation between code and content.

    This way, you can write your Perl script to generate the content and include any client side functionality in the template separately.

提交回复
热议问题