Data transfer from Python CGI to javascript

MRAB python at mrabarnett.plus.com
Fri Aug 9 11:13:59 EDT 2013


On 09/08/2013 07:53, engg at cleantechsolution.in wrote:
> I have written the following program
> #!c:\Python27\Python.exe
> import cgi, cgitb;
> import sys, serial
> cgitb.enable()
> ser = serial.Serial('COM27', 9600)
> myvar = ser.readline()
> print "Content-type:text/html\n\n"
> print """
> <html>
> <head>
> <title>
> Real Time Temperature
> </title>
>    <script type="text/javascript">
>      window.onload = startInterval;
>      function startInterval()
>      {
>          setInterval("startTime();",1000);
>      }
>
>      function startTime(myvar)
>      {
>          document.getElementById('mine').innerHTML ="Temperature" +parseInt(myvar);
>
>      }
>    </script>
> </head>
> <body>
> <h1>Real Time Temperature:</h1>
> <div id="mine"></div>
> </body></html>
> """
>
> It is giving an output of 'NaN' in the output.
> If the python program is run alone it is giving the correct output.
> Can anyone please help.
> Is it also possible to separate the python and the javascript to two different files. If so how will I get/transfer the data in/from HTML .
> Thanks
>
At a guess I'd say that it's because you have:

     setInterval("startTime();",1000);

which will call 'startTime' with no arguments, but:

     function startTime(myvar)

which means that it's expecting an argument.




More information about the Python-list mailing list