我一直在为可能放弃 PHP 做准备,并决定在我的下一个项目中使用 Python,但我已经完全陷入困境,我想知道是否有人可以帮助我。
如果我执行:
$.getJSON('test.php', { testdata: 'hello world' })
在“test.php”中我可以使用
$_GET['testdata']
检索“hello world”。
我似乎找不到 test.py 的等效项:
$.getJSON('test.py', { testdata: 'hello world' })
我已经在网上看到了与 request.get 或 os.environment 相关的代码来获取数据,但我未能进行任何配置。有人有什么建议吗?
我对开发还很陌生,所以如果我错过了一些明显的东西,我深表歉意。
非常感谢
最佳答案
这对我有用:
import cgi
import cgitb #this...
cgitb.enable() #..and this are not really necessary but helps debuging
data= cgi.FieldStorage()
#remove this commant to take a look in the data received by python
#print data
#here you can retrieve the value passed by ajax
print data['testdata'].value
希望它对你有用。
关于javascript - 将 JSON 从 jQuery .getJSON 传递到 Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10232327/