gpt4 book ai didi

javascript - 在 python block 中使用 javascript 变量

转载 作者:行者123 更新时间:2023-11-30 13:34:37 25 4
gpt4 key购买 nike

我想在 python block 中使用 JavaScript 变量。

<script>
$(document).ready(function() {
$("#WO_cpp_id").change(function() {
id = this.selectedIndex;
ajax('{{=URL(r=request,f='get_CIs',vars={'CPP_Id':'#here I want to use id variable')}}', ['WO_cpp_id'], 'WO_ci_id');
})
.change(); }); </script>

提前致谢

最佳答案

您的 Python 代码正在服务器上运行。您的 JavaScript 代码(如引用的那样)正在客户端上运行。所以你不能在 Python 代码中直接使用 JavaScript 变量。您所做的是发送您想要以多种方式从客户端发送到服务器的数据。

其中一种方法是“ajax”。此客户端代码将变量 foo 的内容作为 POST 上的“fooParameter”参数发送到服务器:

var foo = "This is some information";
$.ajax({
url: "myscript.py",
method: "POST",
data: {fooParameter: foo},
success: function(responseData) {
// Successful POST; do something with the response if you want
},
error: function(jxhr, statusText, err) {
// Error, handle it
}
});

更多内容在 jQuery docsthe Wikipedia article on ajax .

关于javascript - 在 python block 中使用 javascript 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5367414/

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