Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

Data transfer from Python CGI to javascript

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


engg at cleantechsolution

Aug 8, 2013, 11:53 PM

Post #1 of 2 (14 views)
Permalink
Data transfer from Python CGI to javascript

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
--
http://mail.python.org/mailman/listinfo/python-list


python at mrabarnett

Aug 9, 2013, 8:13 AM

Post #2 of 2 (9 views)
Permalink
Re: Data transfer from Python CGI to javascript [In reply to]

On 09/08/2013 07:53, engg [at] cleantechsolution 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.

--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.