Asg*_*eir 1 javascript python ajax scripting http
我正在尝试从本地javascript文件(本地运行的HTML/javascript程序的一部分)运行python脚本.
我一直在谷歌搜索这几个小时,并找到了很多解决方案,其中没有一个真正适合我.
这是javascript:
$.ajax({
type: "POST",
url: "test.py",
data: { param: " "}
}).done(function( o ) {
alert("OK");
});
Run Code Online (Sandbox Code Playgroud)
test.py文件与脚本/ html文件位于同一文件夹中.
这是脚本:
#!/usr/bin/python
import os
filepath = os.getcwd()
def MakeFile(file_name):
temp_path = filepath + file_name
with open(file_name, 'w') as f:
f.write('''\
def print_success():
print "sucesss"
''')
print 'Execution completed.'
MakeFile("bla.txt");
Run Code Online (Sandbox Code Playgroud)
正常运行时工作正常.
在我的Firefox控制台上,我收到"格式不正确"的错误,并且脚本没有创建文件.但是,我可以看到Firefox确实获取了脚本,因为我可以通过单击文件名在浏览器中查看它.