问题
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) + '...'
);
}
} );
I found the script here https://stackoverflow.com/a/42592356/9483949 and it seems it worked well for someone earlier.
I'm using Firefox 59.0.1 and Greasemonkey 4.3
Restarting Firefox and reinstalling script didn't help.
回答1:
The doc : https://wiki.greasespot.net/GM.xmlHttpRequest
The GM API was changed. You have to use xmlHttpRequest property of GM class, it is compatibility: GM 4.0+.
Replace GM_xmlhttpRequest
by : GM.xmlHttpRequest
like this :
// ==UserScript==
// ...
// @grant GM.xmlHttpRequest
// ==/UserScript==
GM.xmlHttpRequest({
来源:https://stackoverflow.com/questions/49365651/greasemonkey-gm-xmlhttprequest-is-not-defined-with-the-new-update