javascript - Greasemonkey: "GM_xmlhttpRequest is not defined"新更新

标签 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 并重新安装脚本没有帮助。

最佳答案

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

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

GM_xmlhttpRequest 替换为:GM.xmlHttpRequest,如下所示:

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

GM.xmlHttpRequest({

关于javascript - Greasemonkey: "GM_xmlhttpRequest is not defined"新更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49365651/

相关文章:

javascript - react : Is there a way to refer to another object in the same component's constructor?

javascript - 我不明白如何用 Jest 测试发送 mailgun 是否成功

greasemonkey - 在所有地址上运行我自己的用户脚本有风险吗?

cookies - Greasemonkey 通过通配符阻止 cookie

javascript - 使用 XPath 1.0 查找指向图像的 href 的所有 <a>

javascript - 来自@require 脚本的@grant GM 函数

javascript - Greasemonkey 脚本无法删除元素

javascript - 将属性与 Knockout.js 中多维可观察数组中的搜索字符串进行比较

javascript - 自定义 jQuery 模糊函数在点击事件之前触发

jquery - 使用 jQuery 和 contains() 进行全字匹配