i'm newbie on python, so i'm trying to execute a script python from a javascript.
my script python should to create some directories and files.
python:
import os
#insert project name
name_project = raw_input("give the name of project :")
#create new ionic project
os.system('ionic start '+name_project+' blank')
#access to the project directory
os.chdir(name_project)
#create new platform
os.system('ionic platform add android')
HTML :
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
</head>
<script type="text/javascript" src="jquery-1.11.3.min.js"></script>
<body>
<button id="home" onclick="runscript()" >save</button>
<script type="text/javascript">
function runscript(){
$.ajax({
url: 'myfile.py'
});
}
</script>
</body>
</html>
webservice python:
import sys
import BaseHTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
HandlerClass = SimpleHTTPRequestHandler
ServerClass = BaseHTTPServer.HTTPServer
Protocol = "HTTP/1.0"
if sys.argv[1:]:
port = int(sys.argv[1])
else:
port = 9000
server_address = ('127.0.0.1', port)
HandlerClass.protocol_version = Protocol
httpd = (ServerClass(server_address, HandlerClass))
sa = httpd.socket.getsockname()
print "Serving HTTP on", sa[0], "port", sa[1], "..."
httpd.serve_forever()
the problem now is, when i click on the button "save" nothing appear. but the script is correct and it running if i execute it alone.
if any body have an idea thx