gpt4 book ai didi

javascript - 我如何将数据传递给加载了 $.getScript() 的外部脚本?

转载 作者:搜寻专家 更新时间:2023-11-01 04:52:53 24 4
gpt4 key购买 nike

所以我尝试使用 jquery 的 $.getScript 远程加载 javascript,但我对如何将数据传递到外部脚本感到困惑。

我尝试在调用前设置变量,但它们在加载的脚本中不可用,当我尝试使用查询字符串发送/检索它们时,远程脚本尝试读取基的查询字符串从中调用它的文件,而不是它本身。还有其他方法吗?或者是否有可能让 javascript 文件读取它自己的查询字符串而不是从中调用它的文件(在浏览器中加载)?

// editor ini
var editor_ini = { page: current_page, action: 'edit' };
var foo = 'bar';
// load the editor
$.getScript('assets/desktop/desklets/'+launcher.config.editor+'/execute.js', function(){});

在 execute.js 文件中,editor_inifoo 都不可用,我得到相同的结果:

// load the editor
$.getScript('assets/desktop/desklets/'+launcher.config.editor+'/execute.js', { page: current_page, action: 'edit', foo: 'bar' }, function(){});

因为远程脚本似乎是从原始文档中获取查询字符串,而不是调用文件时使用的字符串。

如果重要的话,我正在尝试使用 query object plugin用于读取查询字符串的 jquery。

最佳答案

在内联 javascript 中声明的全局变量可在使用 $.getScript() 加载的外部 javascript 页面中访问。

关于javascript - 我如何将数据传递给加载了 $.getScript() 的外部脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7440348/

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