简体   繁体   English

带有python文件的AJAX请求的HTML:服务器端未执行

[英]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服务器(例如ApacheNginx) ,也无法安装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.

相关问题 Python在html中显示服务器端图像 - Python display a server-side image in a html Python Web框架:HTML服务器端模板和代码重复 - Python web frameworks: HTML server-side templates and duplication of code 如何在Python中创建服务器端服务以处理来自Web和移动应用程序的HTTP请求? - How do I create a server-side service in Python to handle HTTP requests from web and mobile apps? python服务器端程序来处理电子邮件? - python server-side program to handle email? 无限运行的服务器端python脚本? - Infinite running server-side python script? Python 瓶服务器端缓存 - Python bottle server-side caching 服务器端的AJAX / JSON:将所有参数传递给Python字典(Flask) - AJAX/JSON in server-side: pass all arguments to a Python dictionary (Flask) 服务器端(python)和客户端(javascript)设计与交互 - Server-side(python) and client-side(javascript) design and interaction 使用JavaScript和Google App Engine中的服务器端Python代码动态生成客户端HTML表单控件 - Dynamically generate client-side HTML form control using JavaScript and server-side Python code in Google App Engine 如何使用 FileField 在 django 中浏览服务器端文件? - How to browse server-side files in django with FileField?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM