gpt4 book ai didi

javascript - Bottle .py : sending data via javascript

转载 作者:行者123 更新时间:2023-11-30 06:46:52 24 4
gpt4 key购买 nike

基本上,我想在我的网站上有一个交互式按钮,当点击它时,它会向服务器发送一些数据以便进行检查并显示响应(无需发送表单/重新加载页面)。

我以为会是这样的:

function checkData()
{
var req = new XMLHttpRequest();
var conf = document.getElementById('my_text_area').value;

req.open("GET", 'check_data', true);
req.onreadystatechange = function ()
{
var pre = document.getElementById('check_data_out');
pre.innerHTML = req.responseText;
}

req.send(conf);
return false;
}

在服务器端:

@get('/check_data')
def check_data():
# Process the content and answer something...
content = str(request.is_ajax) + ' - ' + str(request.GET) + ' - ' + str(request.POST)
return content

但这显然行不通。要么这不是通过 javascript 发送数据的正确方式,要么不是在 bottle.py 中访问它的正确方式。

非常感谢向我展示它是如何工作的。

最佳答案

您可以将 dojo 用于客户端逻辑。

var button = dojo.byId('button_id'); // button_id refers to the id of the button you want to click

dojo.connect(button,'onclick',dojo.xhrGet({
url: '/check_data',
handleAs : 'text',
load : function(response){
dojo.byId('button_id').innerHTML = response;
}
}));

关于javascript - Bottle .py : sending data via javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5817296/

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