Greasemonkey:“未定义GM_xmlhttpRequest"新的更新 [英] Greasemonkey: "GM_xmlhttpRequest is not defined" with the new update
问题描述
为什么这个简单的Greasemonkey脚本对我不起作用 https://jsfiddle.net/pghnsw8z/1/?我的意思是,在进行ajax调用时,我没有得到成功的响应,而是得到了错误.
Why this simple Greasemonkey script is not working for me https://jsfiddle.net/pghnsw8z/1/ ? I mean that instead of getting successful response I get error while making an ajax call.
// ==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 找到了该脚本,并且似乎可行对于早先的人来说很好.
I found the script here https://stackoverflow.com/a/42592356/9483949 and it seems it worked well for someone earlier.
我正在使用Firefox 59.0.1和Greasemonkey 4.3
I'm using Firefox 59.0.1 and Greasemonkey 4.3
重新启动Firefox并重新安装脚本没有帮助.
Restarting Firefox and reinstalling script didn't help.
推荐答案
文档: https://wiki.greasespot.net/GM.xmlHttpRequest
GM API已更改.您必须使用GM类的xmlHttpRequest属性,这是兼容性:GM 4.0 +.
The GM API was changed. You have to use xmlHttpRequest property of GM class, it is compatibility: GM 4.0+.
将GM_xmlhttpRequest
替换为:GM.xmlHttpRequest
就像这样:
// ==UserScript==
// ...
// @grant GM.xmlHttpRequest
// ==/UserScript==
GM.xmlHttpRequest({
这篇关于Greasemonkey:“未定义GM_xmlhttpRequest"新的更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!