获得从POST Ajax调用使用的web2py数据

编程入门 行业动态 更新时间:2024-10-25 18:33:36
本文介绍了获得从POST Ajax调用使用的web2py数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在做一个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_vars

They are copied to request.vars also if there is no request.get_vars

更多推荐

获得从POST Ajax调用使用的web2py数据

本文发布于:2023-10-23 14:12:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1521055.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据   POST   Ajax   web2py

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!