Pass variables from Perl to Ajax and back

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • virtualweb
    New Member
    • Aug 2007
    • 30

    Pass variables from Perl to Ajax and back

    Hi everybody, I'm creating a website with HTML / Javascript embeded in perl code. I use perl to get values from a MySQL database which I need to feed a chart created with the javascript code so the chart can be updated on the fly. Everything works perfectly well except I don't know how the perl variable values can be passed to the javascript within the same document.

    Here is abbreviated example code:

    Code:
    #!/usr/bin/perl -w
    use CGI;
    use sctrict;
    
    $Type = 'line';
    $width = '200';
    $line_color ='#FF0000';
    $fillColor = '#FFFF00',
    $height = '20';
    
    ### I NEED TO POPULATE THE BELOW DOTED LINES WITH THE ABOVE VARIABLES  ###
    
    print q~
    
      <script>
    
        $(document).ready(function () {
    
         $("#sparkline4").sparkline([34, 43, 43, 35, 44, 32, 15, 22, 46, 33, 86, 54, 73, 53, 12, 53, 23, 65, 23, 63, 53, 42, 34, 56, 76, 15, 54, 23, 44], {
                type: '........',
                lineColor: '.....', 
                fillColor: '.......',
                width: '......',
                height: '.....'
            });
    
       });
    
    var hellow_world: 'Hello World';
    
    </script>
    ~;
    
    $HELLO_WORLD = "..........";
    
    ### ----- END OF PERL CODE ---- ###

    Also I need to do this the other way around. The value of the hellow_worl javascript variable need to populate the dots in the $HELLO_WORLD perl variable.

    Thanx a million
    webvirtual
Working...