获得从POST Ajax调用使用的web2py数据 [英] Get data from POST ajax call using web2py

查看:334
本文介绍了获得从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数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆