获取整个文件的响应而不是实际响应

2024-04-25 09:22:19 发布

您现在位置:Python中文网/ 问答频道 /正文

实际上,我试图从我的.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

有什么帮助吗??你知道吗


Tags: thepybr脚本datafooisvalue

热门问题