ReferenceError:未定义GM_xmlhttpRequest

时间:2013-05-24 13:37:07

标签: javascript greasemonkey referenceerror gm-xmlhttprequest

我在以下用户脚本代码中获得了一个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);
}
...

首先成功记录GM_info,然后记录ReferenceError。 (我正在使用Firefox / Firebug。)

  

ReferenceError:未定义GM_xmlhttpRequest

为什么我会收到此错误?

3 个答案:

答案 0 :(得分:4)

重新安装脚本修复了问题。我不需要重新启动Firefox,但它可能对其他人有帮助。 Brock's answer为这类问题提供了有用的调试技巧。

答案 1 :(得分:4)

我有同样的问题,为我修复的是在顶部添加:

// @grant        GM_xmlhttpRequest

答案 2 :(得分:2)

自新闻版本(GM 4.0)起,使用Sub Macro_resize ()   With ActiveWindow.Selection.ShapeRange     .Height = 450     .Width = 510     .Left = 30     .Top = 290   End With End Sub 时会发生此错误,因为GM_xmlhttpRequest被替换为GM_xmlhttpRequest

新代码为:

GM.xmlHttpRequest

Greasemonkey: "GM_xmlhttpRequest is not defined" with the new update

相关问题