[英]HTML with AJAX requests to python files : server-side not executed
I want to deliver HTML files with AJAX requests (to a server-side scripting language) on a RedHat server where I don't have root access. 我想在没有root访问权限的RedHat服务器上传递带有AJAX请求的HTML文件(至服务器端脚本语言)。 I can't install HTTP server like Apache or Nginx and can't install PHP too.
我无法安装HTTP服务器(例如Apache或Nginx) ,也无法安装PHP 。
So I thought using Python already included in the RedHat distribution. 因此,我认为使用RedHat发行版中已包含的Python。
Here is the HTML (+ jQuery) code : 这是HTML(+ jQuery)代码:
<script>
function start_ajax_request(){
$.get("request.py", function(data,status){
alert(status);
console.log(data);
});
}
$(document).ready(function(){
start_ajax_request();
});
</script>
1 - I used the built-in HTTP server ( python -m SimpleHTTPServer 8080
), but the Python code isn't executed, the source code of the py file is returned by the AJAX request : 1-我使用了内置的HTTP服务器(
python -m SimpleHTTPServer 8080
),但是未执行Python代码,AJAX请求返回了py文件的源代码:
# -*-coding:utf-8 -*
import json
print json.dumps({"a": 15, "b": 13, "c": 17})
2 - I made some tests with Bottle . 2-我用Bottle做了一些测试。 It doesn't seem the perfect tool to deliver HTML files (I don't need the framework thing).
它似乎不是交付HTML文件的理想工具(我不需要框架的东西)。
When I launch the page in the brower, the AJAX request returns the source code of the py file too. 当我在浏览器中启动页面时,AJAX请求也返回py文件的源代码。
3 - I tried to use Waitress . 3-我尝试使用服务生 。 It seemed more adapted to my needs, but I can't make it works.
它似乎更适合我的需求,但我无法使其正常工作。
What do I need to do to get the python file executed when an AJAX request is made ? 发出AJAX请求时,我需要怎么做才能使python文件执行?
Is this a HTTP server problem or my code is not correct ? 这是HTTP服务器问题还是我的代码不正确?
I want to keep things simple and not invasive. 我想让事情简单而不是侵入性的。 I know practically nothing about Python.
我对Python几乎一无所知。
I don't know very well SimpleHTTPServer, i use cherrypy to serve web pages; 我不太了解SimpleHTTPServer,我使用cherrypy来提供网页; anyway: is request.py executable?
无论如何:request.py可执行吗? First lines of python are like:
python的第一行是这样的:
#!/usr/bin/env python
#-*- coding:utf-8 -*-
print "Content-type: text/html\r\n\r\n"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.