Data transfer from Python CGI to javascript

engg at cleantechsolution.in engg at cleantechsolution.in
Fri Aug 9 02:53:51 EDT 2013


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



More information about the Python-list mailing list