javascript ReferenceError: GM_xmlhttpRequest 未定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16736320/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ReferenceError: GM_xmlhttpRequest is not defined
提问by Kendall Frey
I get a ReferenceError in the following userscript code:
我在以下用户脚本代码中收到一个 ReferenceError:
// ==UserScript==
// @name ...
// @namespace ...
// @description ...
// @include ...
// @grant GM_xmlhttpRequest
// ==/UserScript==
console.log(GM_info);
try
{
console.log(GM_xmlhttpRequest({ method: "GET", url: "http://google.ca/", synchronous: true }).readyState);
}
catch (e)
{
console.log(e);
}
...
It first logs GM_info
successfully, then logs the ReferenceError. (I'm using Firefox/Firebug.)
它首先GM_info
成功记录,然后记录 ReferenceError。(我正在使用 Firefox/Firebug。)
ReferenceError: GM_xmlhttpRequest is not defined
ReferenceError: GM_xmlhttpRequest 未定义
Why do I get this error?
为什么会出现此错误?
采纳答案by Kendall Frey
Reinstalling the script fixed the problem. I didn't need to restart Firefox, but it may be helpful for other people. Brock's answerhas helpful debugging tips for problems like this.
重新安装脚本解决了问题。我不需要重新启动 Firefox,但它可能对其他人有帮助。Brock 的回答对此类问题提供了有用的调试技巧。
回答by Kendall Frey
I had the same problem, and what fixed it for me was adding this at the top:
我遇到了同样的问题,对我来说修复它的是在顶部添加这个:
// @grant GM_xmlhttpRequest
回答by A-312
Since the news version (GM 4.0) this error happened when you use GM_xmlhttpRequest
because GM_xmlhttpRequest
was replaced by : GM.xmlHttpRequest
.
从新闻版本(GM 4.0)开始,这个错误在你使用时发生,GM_xmlhttpRequest
因为GM_xmlhttpRequest
被替换为 : GM.xmlHttpRequest
。
The new code is :
新代码是:
// ==UserScript==
// @name ...
// @namespace ...
// @description ...
// @include ...
// @grant GM.xmlHttpRequest
// ==/UserScript==
console.log(GM_info);
try
{
console.log(GM.xmlHttpRequest({ method: "GET", url: "http://google.ca/", synchronous: true }).readyState);
}
catch (e)
{
console.log(e);
}
//...
Greasemonkey: "GM_xmlhttpRequest is not defined" with the new update