how to send information from cgi script to JavaScript?

how to send information from cgi script to JavaScript?

Postby pfeldman » Thu May 16, 2013 10:41 pm

I've been developing a bunch of online puzzle solvers (see, e.g., http://phillipmfeldman.org/English/hangman.html). I've gotten the hang of sending information from an html form to a Python script via the cgi interface, but so far haven't been able to figure out how to send information in the reverse direction. In particular, I'd like to be able to calculate a string or integer and then store this information into a JavaScript variable. Is there a way to do this?

Phillip
pfeldman
 
Posts: 2
Joined: Thu May 16, 2013 10:36 pm

Re: how to send information from cgi script to JavaScript?

Postby metulburr » Fri May 17, 2013 3:15 am

Code: Select all
import os
import cgi
import cgitb
cgitb.enable()

pid_data = str(os.getpid())

html = """Content-type: text/html

<html>
<head><title>Test Page</title>
<script type="text/javascript">
alert('pid_data is {PID}')
</script>
</head>




html: {PID}<br>
</body>
</html>""".format(PID=pid_data)

print(html)
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1413
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: how to send information from cgi script to JavaScript?

Postby pfeldman » Sun May 19, 2013 4:47 pm

Your script is interesting, and I'm able to run it, but it doesn't seem directly applicable to my problem.

I've tried using a server-side include, but can't seem to make that work.

Any other suggestions are welcome.
pfeldman
 
Posts: 2
Joined: Thu May 16, 2013 10:36 pm

Re: how to send information from cgi script to JavaScript?

Postby metulburr » Sun May 19, 2013 6:12 pm

it doesn't seem directly applicable to my problem


You would just instead of using it to make an alert message, insert it into var
Code: Select all
var x={PID};
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1413
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: how to send information from cgi script to JavaScript?

Postby GeraldKevin » Thu Jul 04, 2013 5:54 am

It is also not taken by Var also. Any other suggestions.
Last edited by stranac on Fri Jul 26, 2013 11:04 am, edited 1 time in total.
Reason: Could be spam. I deleted the users sig, because that part was definitely spammy
GeraldKevin
 
Posts: 1
Joined: Thu Jul 04, 2013 5:32 am


Return to Web Development

Who is online

Users browsing this forum: No registered users and 1 guest