如何使用jQuery执行服务器端Python脚本? [英] How do you execute a server-side Python script using jQuery?

查看:315
本文介绍了如何使用jQuery执行服务器端Python脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的Python文件,名为python1.py,其内容是:

I have a very simple Python file, called python1.py, whose contents are:

f = open('C:\\Temp\\test.txt', 'w')
f.write('Succeeded')
f.close()

我想从JavaScript执行此,像这样:

I wish to execute this from JavaScript, like so:

jQuery.ajax({
   type: "POST",
   url: "/cgi-bin/python1.py",
   success: function (msg) {
       alert("Data Saved: " + msg);
   }
});

然而,发生的事情是,我得到一个警告,向我展示了Python脚本的内容。该文件C:\ TEMP \ test.txt的还没有生成,所以显然是不执行的Python

However, all that happens is that I get an alert showing me the contents of the Python script. The file C:\Temp\test.txt does not get created, so clearly the Python was not executed.

如何做我说服code执行Python脚本,而不是仅仅看它?

How do I persuade the code to execute the Python script instead of just reading it?

推荐答案

您可以直接从浏览器中执行脚本。这看起来更像是一个网络服务器的配置问题,而不是jQuery的

Are you able to execute the script directly from the browser. This looks more like a webserver config issue than jquery's

这篇关于如何使用jQuery执行服务器端Python脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆