实际上,我试图从我的.py脚本中得到一些响应,但没有得到响应,而是得到了整个文件。
这是javascript文件中的ajax调用
$.ajax({
url: "py/simple.py",
type: "POST",
data: {foo: 'bar', bar: 'foo'},
success: function(response){
log(response);
$("#div").html(response);
}
});
这是py脚本
import cgi, cgitb
cgitb.enable() # for troubleshooting
#the cgi library gets vars from html
data = cgi.FieldStorage()
#this is the actual output
print "Content-Type: text/plain\n"
print "The foo data is: " + data["foo"].value
print "<br />"
print "The bar data is: " + data["bar"].value
print "<br />"
print data
我得到的回应是
import cgi, cgitb
cgitb.enable() # for troubleshooting
#the cgi library gets vars from html
data = cgi.FieldStorage()
#this is the actual output
print "Content-Type: text/plain\n"
print "The foo data is: " + data["foo"].value
print "<br />"
print "The bar data is: " + data["bar"].value
print "<br />"
print data
有什么帮助吗??你知道吗
您的Web服务器配置错误。您需要告诉它您的请求是执行cgi-bin(而不是返回文件内容)。比如:
你可以阅读更多https://httpd.apache.org/docs/2.2/howto/cgi.html
相关问题 更多 >
编程相关推荐