2013-09-21 31 views
0

我是路过值从jQuery的.getJSON()的PHP文件有:

jQuery的

<script> 
function loadContent(href){ 
    $.getJSON("http://path/to/file.php", {cid: href, format: 'json'}, function(results){ 
     $("#my_div").html(""); 
     $.each(results, function(key,value){ 
      $("#my_div").append(value.content); 
     }); 
    }); 
} 
</script> 

PHP

$href = $_GET['cid']; 

这意味着我可以通过href值工作从jQuery到PHP文件中的$_GET

我已经关掉我的应用程序到Python和想知道的Python相当于是什么:

$href = $_GET['cid']; 

新的环境是MongoDB的,PyMongo和瓶。瓶我相信是使用wsgi

我见过像一种方式的一些参考:

href = request.GET['cid'] 

这将是做到这一点的最好办法/这是否工作(这是很难测试)?

更新:上述不起作用。

+0

这样看来如此。 –

+0

任何人都可以建议如何测试如果Python文件是从jQuery获取值?我无法从Python文件中“提醒”,是否有相当的? – user1063287

+0

你不能写一个只是'alert()'响应的jquery调用吗?并让它返回你读的内容? –

回答

0

解决的办法是:

from bottle import response, request 
href = request.GET.cid # where 'cid' is the key name of the value you passed in, see original post for that implementation. 

如果你想将数据发送回jQuery的JSON格式,你可以这样做:

from bottle import response, request 
from bson.json_util import dumps 
href = request.GET.cid 
# do things with variable here 
response.content_type = 'application/json' 
return dumps(your_variable) 
相关问题