I would like to pass data from a javascript to a python script called test.py, when the button is clicked.
The web page contains the following script:
<script>
$(document).ready(function(){
$("button").click(function(){
$.post("/cgi-bin/test.py",
{ name: "Zara" };
});
});
});
</script>
<button type="submit">Run</button>
Here is the test.py that runs in the same server of the web page:
#!/usr/python
print('Content-Type: text/html; charset=utf-8\n')
import sys
file = open('/var/www/cgi-bin/temp.txt','w')
file.write(sys.argv[1])
file.close()
I expected that the temp.txt contains the name Zara. But temp.txt is empty.
So my question is:
How the python script gets the argument name from javascript? Can I use sys.argv or i need another python library?
/cgi-bin/test.pyas the first argument and the arguments you need to send to the python script as the next arguments. then you should be able to use sys.argv in your py script