我目前正在使用 Jquery 的 .load() 函数异步插入页面片段。在我从中加载页面片段的 URL 中,我还设置了一个 Javascript 全局变量值(在脚本标记中)。
var loaded_variable = 'value1'
有没有办法可以使用 .load() 函数插入页面片段并检索 的值loaded_variable
,类似于以下代码:
function loadProducts(url) {
$('#mainplace').load(url + ' #submain', function() {
current_variable = loaded_variable;
});
}
I am aware that script blocks are used when a selector expression is appended to the URL, so if the .load() function won't work, I'm open to other Jquery functions that can accomplish this.
额外信息:我从中加载的 URL 是用 HTML 和 Python (Web2py) 编写的;相同的 Python 变量用于呈现页面片段并设置loaded_variable
值。