请问我做错什么了。我想在服务器端运行一个非常基本的python脚本,并在客户端获取返回值(即javascript) 我的python脚本是:
// Hello.py
--------------------------
import sys
def hello(str):
print('Hello ' + str)
return 1
if __name__ == '__main__':
hello(*sys.argv[1:])
我的Ajax呼叫:
function getAjax(url, data){
return $.ajax({
type: 'POST',
url : url,
data: data,
success: function(response) {
return response;
}
});
}
getAjax("./scripts/hello.py", 'John').done(function(response){
console.log(response);
});
运行getAjax
时,console.log(response)
语句只打印Python脚本中的文本(即代码)。请问我在这里错过了什么步骤?你知道吗
您需要一个服务器来将来自浏览器的http请求链接到网络目标的特定端口(默认为80)上,并获得特定脚本的响应,在python中这样的本地测试最简单的用法是使用simplehttpserver:https://docs.python.org/2/library/simplehttpserver.html
相关问题 更多 >
编程相关推荐