gpt4 book ai didi

python - 使用 web2py 从 POST ajax 调用获取数据

转载 作者:行者123 更新时间:2023-11-28 20:50:17 25 4
gpt4 key购买 nike

我正在对 python 函数进行 AJAX 调用。该函数根据发送给该函数的信息进行数据库查询。

我不知道如何获取发送到函数的变量。

我使用的是 request.vars.variableName,我知道这个函数是有效的,只是没有接收到正确使用的变量。如何使用 web2py 从 python 函数获取 POST 发送的变量?

预计到达时间:这是我使用的代码

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}
);

错误在“data: typeSelected”行,变量名没有关联任何数据,所以python查询:

cost=db(db.balloonprices.type==request.vars.typeSelected).select(db.balloonprices.cost)

正在寻找 ""而不是数据库中实际存在的任何内容。

最佳答案

这对我有用:

AJAX 调用:

       $.ajax({
type: "POST",
url: "/app/func",
data: "array="+JSON.stringify(tempArray)
}).done(function( msg ) { });

Controller :

def func():    
temparray = json.loads(request.post_vars.array)

希望对你有帮助

关于python - 使用 web2py 从 POST ajax 调用获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12781187/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com