Greasemonkey:使用新更新“GM_xmlhttpRequest未定义”

时间:2018-03-19 14:43:24

标签: javascript greasemonkey greasemonkey-4

为什么这个简单的Greasemonkey脚本对我不起作用https://jsfiddle.net/pghnsw8z/1/?我的意思是,在进行ajax调用时,我得到错误而不是成功响应。

// ==UserScript==
// @name        _Starter AJAX request in GM, TM, etc.
// @match       *://php.net/*
// @grant       GM_xmlhttpRequest
// @connect     php.net
// ==/UserScript==

GM_xmlhttpRequest ( {
    method:     'GET',
    url:        'http://php.net/',
    onload:     function (responseDetails) {
                    // DO ALL RESPONSE PROCESSING HERE...
                                alert(responseDetails);
                    console.log (
                        "GM_xmlhttpRequest() response is:\n",
                        responseDetails.responseText.substring (0, 80) + '...'
                    );
                }
} );

我在这里找到了这个脚本https://stackoverflow.com/a/42592356/9483949,而且它似乎对以前的人有用。

我正在使用Firefox 59.0.1和Greasemonkey 4.3

重新启动Firefox并重新安装脚本没有帮助。

1 个答案:

答案 0 :(得分:2)

文档:https://wiki.greasespot.net/GM.xmlHttpRequest

GM API已更改。你必须使用GM类的XMLHttpRequest的属性,它是兼容性:GM 4.0 +

GM_xmlhttpRequest替换为:GM.xmlHttpRequest像这样:

// ==UserScript==
// ...
// @grant         GM.xmlHttpRequest
// ==/UserScript==

GM.xmlHttpRequest({