Data transfer from Python CGI to javascript

E

engg

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
 
M

MRAB

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top