我在做一个AJAX调用一个python函数。该函数的作用的基础上发送给函数的信息的数据库查询。
我不知道如何获取发送到该函数的变量。
我是用request.vars.variableName了,我知道该函数是有效的,它只是不接受变量正确使用。如何获得职位从一个Python函数发送变量,使用的web2py?
ETA:这是code我用
jQuery.ajax( {类型:POST, 网址:../../Printed/printedballoons/cost.json',// Python函数 数据:typeSelected,//发送到服务器的数据 数据类型:JSON, 错误:函数(MSG){$(#ajaxerror)HTML(味精);}, 成功:功能(数据){ balloonPrice = data.cost; }, 超时:2000} );
该错误是在数据:typeSelected行,与任何数据相关的变量名wasnt,所以蟒蛇查询:
成本= DB(db.balloonprices.type == request.vars.typeSelected)。选择(db.balloonprices.cost)
一直在寻找的,而不是一个东西,实际上是在数据库中。
解决方案 request.post_vars
它们复制到 request.vars 另外,如果没有request.get_vars
I'm making an AJAX call to a python function. That function does a database query based on the information sent to the function.
I can't work out how to get the variable that is sent to the function.
I was using request.vars.variableName, and I know the function is valid, it's just not receiving the variable to use properly. How do I get POST sent variables from a python function, using web2py?
ETA: This is the code I was using
jQuery.ajax( {type: "POST", url: '../../Printed/printedballoons/cost.json', //python function data: typeSelected,//data sent to server dataType: 'json', error: function(msg){$("#ajaxerror").html(msg);}, success: function(data){ balloonPrice = data.cost; }, timeout: 2000} );The error was in the "data: typeSelected" line, the variable name wasnt associated with any data, so the python query:
cost=db(db.balloonprices.type==request.vars.typeSelected).select(db.balloonprices.cost)was looking for "" as opposed to a anything that actually is in the database.
解决方案 request.post_varsThey are copied to request.vars also if there is no request.get_vars
更多推荐
获得从POST Ajax调用使用的web2py数据
发布评论